Overview

Thumbnailer is a fast, easy to use image resizer script. It has many options you can tweak for the best results. This script also supports generation of dummy images.

Thumbnailer caches the generated image, that way you won't notice any difference between loading an image or a thumbnail. It has been tested in different sites and it lives up to its reputation!

Features

  • Easy to use script, just upload it and link to it!
  • Easy to read code
  • Meny options to tweak
  • You can also use it without outputting the image
  • No performance/speed issues

How to use

First download the script and place it in the root of your server. Now it's ready to use!

Of cource you must tell the script which image to process. All the parameters are passed as $_GET parameters. This is how we pass image path to it:

/thumbnailer.php?img=/sample.jpg
					

Now it displays our image, but lets resize it!

/thumbnailer.php?img=/sample.jpg&h=200
					

That's it! You've got a working thumbnail. You can pass it into "src" of an image-tag or as background-image in css...

Examples

I'll explain most of the functions here.

Width (w)

Width, "w" (default "0"), is the maximum width that a thumbnail can be.

/thumbnailer.php?img=/sample.jpg&w=100
					

Height (h)

Height, "h" (default "0"), is the maximum height that a thumbnail can be.

/thumbnailer.php?img=/sample.jpg&h=200
					

Resize (resize)

Resize, "resize" (default "true"), controls the final dimensions of your thumbnail:
- if set to "true", the final image will be the same ratio as the original image.
- if set to "false", the final image will have the given dimensions.

/thumbnailer.php?img=/sample.jpg&h=200&resize=true
/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false
					

Fill (fill)

Fill, "fill" (default "true"), is the same as crop. This only works if resize is set to false
- if set to "true", the image will be cropped and will fill the frame.
- if set to "false", the final image will not be cropped and you'll see the full image in the frame. Based on the image, there can be bars around the picture

/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false&fill=true
/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false&fill=false
					

Background (bg)

Background, "bg" (default "ffffff"), is the background color you'll see on the dummy image or if there are bars visible. You can pass short hex as parameter: "333"

Foreground, "fg" (default "eeeeee"), is the border color on the dummy image

/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false&fill=false&bg=777
/thumbnailer.php?img=/non-existing-image.jpg&h=200&w=200&bg=777&fg=222
					

Boldness (boldness)

Boldness, "boldness" (default "2"), is the stroke width. Only seen on a dummy image

/thumbnailer.php?img=/non-existing-image.jpg&h=200&w=200&bg=777&fg=555&boldness=10
					

Quality (quality)

Quality, "quality" (default "90"), is the .jpg quality. Change it if you want to save some bandwidth.

/thumbnailer.php?img=/sample.jpg&h=200&quality=5
					

Enlarge (enlarge)

Enlarge, "enlarge" (default "true"), is the setting that prevents enlarging of small images if the dimensions of the thumbnailer are bigger. On the left the setting is set to "true", on the right to "false"

/thumbnailer.php?img=/sample_small.png&h=200&w=200&resize=false
/thumbnailer.php?img=/sample_small.png&h=200&w=200&resize=false&enlarge=false
					

Scale (scale)

Scale, "scale" (default "1"), lets you specify the scale of the thumbnail. Useful for providing the user with image for high DPI screens. Note: there is a shortcut for providing the user with a double scale image: add @2x to the filename

/thumbnailer.php?img=/sample.jpg&h=200&w=200
/thumbnailer.php?img=/sample.jpg&h=200&w=200&scale=2
/thumbnailer.php?img=/sample@2x.jpg&h=200&w=200
					

Mirror (mirror)

Mirror, "mirror" (default ""), lets you mirror the image. You can pass "vertical", "horizontal" or "horizontal,vertical" ("vertical,horizontal" is the same)

/thumbnailer.php?img=/sample.jpg&h=200&w=200&mirror=vertical
/thumbnailer.php?img=/sample.jpg&h=200&w=200&mirror=horizontal
/thumbnailer.php?img=/sample.jpg&h=200&w=200&mirror=horizontal,vertical
					

Advanced options and tweaking

Default image (default)

Default image, "default" (default ""), is the default image that will be used if the image is not found.

/thumbnailer.php?img=/non-existing-image.jpg&default=/existing-default-image.jpg
					

Transparency (transparent)

Transparency, "transparent" (default "true"), is the .png image transparency. The bars around the image will be transparent too if set to true. Note: this only works if image type is .png!

Type (type)

Type, "type" (default ""), is the output image type. If set to "" (empty) the original type will be used.

Go ahead, inspect the image below, the output type is .png and it's transparent.

/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false&fill=false&type=png
					

Cache time (cachetime)

Cache time, "cachetime" (default "7"), number of days the image will be cached on the client-side.

/thumbnailer.php?img=/sample.jpg&h=200&cachetime=31
					

Position (position)

Position, "position" (default "center"), is the position of the image inside the thumbnails. Possible values: "left", "top", "center", "right", "bottom".

/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false&fill=false&pos=left
/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false&fill=false&pos=center
/thumbnailer.php?img=/sample.jpg&h=200&w=200&resize=false&fill=false&pos=right
					

Download (download)

Download, "download" (default ""), is the file name that will be used when download is initiated. Click here to download the sample image.

/thumbnailer.php?img=/sample.jpg&h=200&w=200&download=sample-image
					

Filter (filter)

Filter, "filter" (default ""), lets you apply one or multiple filters to the image.

/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=negate
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=grayscale
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=brightness,50
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=contrast,240
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=colorize,55,1,33
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=edgedetect
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=emboss
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=guassianblur
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=blur
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=meanremoval
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=smooth,3
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter=pixelate,4,true
/thumbnailer.php?img=/sample.jpg&h=200&w=200&filter[]=negate&filter[]=grayscale
					

Setting root and cache paths

Maybe you've noticed it already, but the thumbnailer.php is not located at my servers root. The cache path is also not in the root. They are both in this path: "/archive/thumbnailer/". This is how you set custom paths:

$root = realpath(getcwd().'/../../');
$cacheRelativePath = '/archive/thumbnailer/cache';
$thumb = new X_Image_Thumbnailer($_GET, $root, $cacheRelativePath);
					

Other settings

There are some other settings you can change in the code:
- You can temporary turn off caching
- You can change safe extensions if you want to

Source

You can find the source code on Github.

Don't hesitate to read the code, you can find there some public methods you can use.

Support

Any questions regarding bugs, requests and the source code itself should be asked on Github. Note: I will try to reply to all mails, but I can't promise anything

Download(v.: 1.0.19)

Current options

These are current options:

  • Basic:

    • Image path (img)
    • Width (w)
    • Height (h)
    • Resize (resize)
    • Fill (fill)
    • Background (bg)
    • Foreground (fg)
    • Stroke width (boldness)
    • Quality (quality)
    • Enlarge (enlarge)
    • Scale (scale)
    • Mirror (mirror)
  • Advanced:

    • Default image (default)
    • Transparency (transparent)
    • Image type (type)
    • Cache time (cachetime)
    • Position (pos)
    • Download name (download)
    • Filter (filter)

Make sure you read the documentation to know how to use these options!