spescina / imgproxy

Image proxy for Laravel based on Timthumb. It's intended to be a replacement of spescina/timthumb
19 stars 2 forks source link

Build Status Coverage Status

ImageProxy

Laravel 4 package for image cropping and resizing on the fly. It uses Timthumb under the hood.

Install && Usage

Add in composer.json

"require": {
    "spescina/imgproxy": "2.x"
}

Run composer update

Add the service provider in the app/config/app.php file

"Spescina\Imgproxy\ImgproxyServiceProvider"

Publish the package assets running php artisan asset:publish spescina/imgproxy

Publish the package config running php artisan config:publish spescina/imgproxy

ImageProxy is configured to use Apache by default. If you are using nginx, add the following to your site configuration file:

rewrite ^/packages/spescina/imgproxy/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/(.*) /packages/spescina/imgproxy/timthumb.php?w=$1&h=$2&zc=$3&q=$4&src=$5;

Use the package facade to generate the resource url

ImgProxy::link("path/to/image.jpg", 100, 80)

This will generate a link like this

http://www.yourdomain.com/packages/spescina/imgproxy/100/80/path/to/image.jpg

that generates an image with dimensions 100 x 80 using the original image.jpg stored in the public/path/to folder.

Parameters

The link function accepts 5 paramaters

Zoom/Crop

These are the supported values

Config

Package config

After publishing the package config file it's possible to change the package behaviour in the app/config/packages/spescina/imgproxy/config.php file.

These are the current options:

Timthumb config

It's possible to edit timthumb config in the public/packages/spescina/imgproxy/timthumb-config.php file.

These, at the moment, are the default values

define ("DEBUG_ON", false);

define ("DEBUG_LEVEL", 3);

define ("FILE_CACHE_MAX_FILE_AGE", 86400);

define ("FILE_CACHE_SUFFIX", ".imgproxy.cache");

define ("FILE_CACHE_PREFIX", "");

define ("FILE_CACHE_DIRECTORY", "../../../../app/storage/cache/imgproxy");

define ("NOT_FOUND_IMAGE", "./nophoto.gif");

define ("ERROR_IMAGE", "./nophoto.gif");

define ("PNG_IS_TRANSPARENT", FALSE);

define ("DEFAULT_Q", 90);

Full nginx example for Laravel Forge

server {
    rewrite_log on;

    listen 80;
    server_name my_site.com;
    root /home/forge/my_site.com/public;

    auth_basic "Restricted";
    auth_basic_user_file /home/forge/my_site.com/public/.htpasswd;

    # FORGE SSL (DO NOT REMOVE!)
    # ssl on;
    # ssl_certificate;
    # ssl_certificate_key;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        rewrite ^/packages/spescina/imgproxy/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/(.*) /packages/spescina/imgproxy/timthumb.php?w=$1&h=$2&zc=$3&q=$4&src=$5;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/my_site.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}