montes / resize-and-watermark by montesjmm

Resize and Watermark for Laravel resizes and watermarks your pictures easily
150
1
1
Package Data
Maintainer Username: montesjmm
Maintainer Contact: javier@montesjmm.com (Montes)
Package Create Date: 2014-05-24
Package Last Update: 2016-03-16
Language: PHP
License: MIT
Last Refreshed: 2021-07-28 03:10:35
Package Statistics
Total Downloads: 150
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

Build Status

#Resize And Watermark (images) Easily automate picture upload, generating of multiple sizes and watermarking if needed.

##Laravel 5.2 Installation

  1. Add to your composer require: "montesjmm/resize-and-watermark": "~0.3"
  2. Add service provider to your config/app.php: Montesjmm\ResizeAndWatermark\ResizeAndWatermarkServiceProvider::class,
  3. Add alias to your config/app.php aliases: 'ResizeAndWatermark' => Montesjmm\ResizeAndWatermark\ResizeAndWatermark::class,
  4. composer update
  5. php artisan vendor:publish
  6. php artisan migrate
  7. composer dump-autoload -o
  8. php artisan db:seed --class=RwPicturesSizesTableSeeder

##Examples

####Download and generate sizes from image url

$resizer = new ResizeAndWatermark;
$picture = $resizer->store('http://example.com/image.jpg');

echo $picture->html('small'); // <img src="http://mysite.com/uploads/2015/03/20150327-picture_small.jpg">

echo $picture->html('big'); // <img src="http://laravel5.app/uploads/2015/03/20150327-picture_big.jpg">

####Generate sizes of form uploaded image

$resizer = new ResizeAndWatermark;
$file = Input::file()['file'];
$picture = $resizer->store($file);

echo $picture->html('small'); // <img src="http://mysite.com/uploads/2015/03/20150327-picture_small.jpg">

Example App

####app/Http/routes.php

Route::get('/', 'WelcomeController@index');
Route::post('/', 'WelcomeController@index');

####app/Http/controllers/WelcomeController.php

<?php namespace App\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Input;
use Montesjmm\ResizeAndWatermark\ResizeAndWatermark;

class WelcomeController extends Controller {

	public function index()
	{
		if (Request::isMethod('post')) {
			$resizer = new ResizeAndWatermark;

			$file = Input::file()['file'];

			$picture = $resizer->store($file);

			return '<img src="' . $picture->url('small') . '">';
		}

		return view('welcome');
	}
}

####resources/views/welcome.blade.php

<html>
	<head>
		<title>Resize And Watermark Test</title>
	</head>
	<body>
		<form method="post" enctype="multipart/form-data">
			<input type="hidden" name="_token" value="{{{ csrf_token() }}}">
			<input type="file" name="file">
			<input type="submit" value="send">
		</form>
	</body>
</html>

When you upload a picture this will be the result in disk:

private-uploads/2015/03/20150326-picture_orig.jpg
public/uploads/2015/03/20150326-picture_bigger.jpg
public/uploads/2015/03/20150326-picture_big.jpg
public/uploads/2015/03/20150326-picture_medbig.jpg
public/uploads/2015/03/20150326-picture_medium.jpg
public/uploads/2015/03/20150326-picture_small.jpg
public/uploads/2015/03/20150326-picture_thumb.jpg
public/uploads/2015/03/20150326-picture_tiny.jpg

"laravel/private-uploads" and "laravel/public/uploads" must be writable.

Config

at config/resize-and-watermark.php you can setup the routes for the watermarking files if you want watermarking.