Thumbnailer
public class Thumbnailer
| Constant Summary | |
|---|---|
| final static int | Constant used in round() method. |
| final static int | Constant used in round(), logoText() and logoPhoto() methods. |
| final static int | Constant used in round(), logoText() and logoPhoto() methods. |
| final static int | Constant used in logoText() and logoPhoto() methods. |
| final static int | Constant used in round(), logoText() and logoPhoto() methods. |
| final static int | Constant used in round(), logoText() and logoPhoto() methods. |
| Field Summary | |
|---|---|
| static array | List of allowed mime types. |
| string | Full path to the source image. |
| string | Image file name. |
| int | Align setting for text/image watermarks. |
| string | Image mime type. |
| callback | Function used to open the image. |
| resource | Image resource. |
| resource | Thumb resource. |
| int | Thumb height |
| int | Thumb width |
| Method Summary | |
|---|---|
| void | __construct(string file) Creates Thumbnailer object using prepare() |
| static array | batch(function callback, string in) Batch mode helper. |
| static array | colorHex(string hex) Hex color helper. |
| static array | colorRGB(int r, int g, int b) Color helper. |
| static Thumbnailer | create(string file) Thumbnailer creator. |
| protected resource | createImage(int width, int height) Creates internal php image (preserves png/gif transparency). |
| Thumbnailer | effectCustom(array matrix, float offset) Apply custom effect on the image. |
| Thumbnailer | Grayscale helper. |
| resource | Resource getter. |
| Thumbnailer | header() Helper sends headers to display thumb directly into the browser. |
| void | im(resource dim, resource sim, int dx, int dy, int sx, int sy, int dw, int dh, int sw, int sh, int q) Resample image more quickly. |
| Thumbnailer | logoAlign(int align) Set text align for logoText() or logoPhoto() watermark. |
| Thumbnailer | logoPhoto(string photo, int x, int y, int alpha) Puts image watermark on the thumb at $x and $y position from the corner set by logoAlign(). |
| Thumbnailer | logoText(string text, string font, int size, int x, int y, array color) Puts text based watermark on the thumb at $x and $y position from the corner set by logoAlign(). |
| void | prepare(string file) Prepares the image to be opened. |
| string | randomName(int length) Helper generates random name for the thumbnail. |
| array | readExif(string sections) Retrieve EXIF data from the image. |
| Thumbnailer | round(int corner_radius, array color, int corners) Round thumb corners using antialiasing. |
| mixed | save(string file, int quality) Saves created the result. |
| static void | setAllowed(array allowed) Sets allowed mime types. |
| Thumbnailer | thumbFixed(int width, int height) Create a fixed size thumbnail. |
| Thumbnailer | thumbSquare(int size) Create a square thumbnail. |
| Thumbnailer | thumbSymmetric(int width, int height) Creates scaled thumbnail of maximum width $width and maximum height $height. |
| Thumbnailer | thumbSymmetricHeight(int height) Create a thumbnail with fixed height and scaled width. |
| Thumbnailer | thumbSymmetricWidth(int width) Create a thumbnail with fixed width and scaled height. |
| static mixed | upload(string fieldName, callback callback) Upload helper. |
public final static int ALL = 15
Constant used in round() method.
public final static int BOTTOM_LEFT = 4
Constant used in round(), logoText() and logoPhoto() methods.
public final static int BOTTOM_RIGHT = 8
Constant used in round(), logoText() and logoPhoto() methods.
public final static int CENTER = 0
Constant used in logoText() and logoPhoto() methods.
public final static int TOP_LEFT = 1
Constant used in round(), logoText() and logoPhoto() methods.
public final static int TOP_RIGHT = 2
Constant used in round(), logoText() and logoPhoto() methods.
public static array $allowed = array(...)
List of allowed mime types. By default only allowed mime types are JPEG, GIF and PNG.
public string $file
Full path to the source image.
public string $filename
Image file name.
public int $logoAlign = self::BOTTOM_LEFT
Align setting for text/image watermarks.
public string $mime
Image mime type.
public callback $openfunc
Function used to open the image.
public resource $resource = null
Image resource. Opened image source in prepare() will be held here.
public resource $thumb
Thumb resource.
public int $thumb_height
Thumb height
public int $thumb_width
Thumb width
public void __construct(string file)
Creates Thumbnailer object using prepare()
public static array batch(function callback, string in)
Batch mode helper. For more information about the input mask please refer to php's glob function manual.
Example usage:
function callb(Thumbnailer $th) {
$filename=$th->randomName();
$th->thumbFixed(120,90)->round()->save('/save/path'.$filename);
return $filename;
}Thumbnailer::batch('callb', '/read/path/*.jpg');
public static array colorHex(string hex)
Hex color helper. For example black is Thumbnailer::colorHex('#000000')
public static array colorRGB(int r, int g, int b)
Color helper. For example black is Thumbnailer::colorRGB(0,0,0)
public static Thumbnailer create(string file)
Thumbnailer creator. Creates thumbnailer object for inline scripting, i.e.:
Thumbnailer::create('photo.jpg')->thumFixed(120,90)->header()->save();
protected resource createImage(int width, int height)
Creates internal php image (preserves png/gif transparency).
public Thumbnailer effectCustom(array matrix, float offset)
Apply custom effect on the image.
Example usage:
// this code will apply gaussian blur on the thumb
$thumbObject
->thumbSquare(200,200)
->effectCustom(array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0)))
->save('output_with_blur.jpg');
public Thumbnailer effectGray()
Grayscale helper. Turns image grayscale. This method can be chained.
public resource getResource()
Resource getter.
public Thumbnailer header()
Helper sends headers to display thumb directly into the browser. This method can be chained.
public void im(resource dim, resource sim, int dx, int dy, int sx, int sy, int dw, int dh, int sw, int sh, int q)
Resample image more quickly.
public Thumbnailer logoAlign(int align)
Set text align for logoText() or logoPhoto() watermark.
Correct values are Thumbnailer::TOP_LEFT, Thumbnailer::TOP_RIGHT, Thumbnailer::BOTTOM_LEFT, Thumbnailer::BOTTOM_RIGHT and Thumbnailer::CENTER.
This method can be chained.
public Thumbnailer logoPhoto(string photo, int x, int y, int alpha)
Puts image watermark on the thumb at $x and $y position from the corner set by logoAlign(). Default corner is bottom left.
Alpha should be between 0 and 100. Use it only with PNG images though.
This method can be chained.
public Thumbnailer logoText(string text, string font, int size, int x, int y, array color)
Puts text based watermark on the thumb at $x and $y position from the corner set by logoAlign(). Default corner is bottom left.
$color should be an array of (R,G,B) or use colorHex(), colorRGB() helpers.
$font - path to the TrueType font
This method can be chained.
public void prepare(string file)
Prepares the image to be opened.
Method checks if file actually exists. If not it checks if file is remotely based. If it is, Thumbnailer creates a temporary file and tries to download the file. When image is ready it tries to get its mime type to set save function and open function to be able to work and save the results. In the end Thumbnailer opens the image and is ready to operate.
public string randomName(int length)
Helper generates random name for the thumbnail.
Example usage:
$th=Thumbnailer::create('image.jpg');$fileName=$th->randomName();
$th->round()->save($fileName);
echo 'File was saved as '.$filename;
public array readExif(string sections)
Retrieve EXIF data from the image.
Example usage:
print_r($thumbnailerObject->readExif());
public Thumbnailer round(int corner_radius, array color, int corners)
Round thumb corners using antialiasing.
public mixed save(string file, int quality)
Saves created the result.
If $file is not specified file will be flushed into the browser. If so use header() helper to send proper headers.
Quality setting is used only for JPEG images. PNG ignores this completely.
public static void setAllowed(array allowed)
Sets allowed mime types.
public Thumbnailer thumbFixed(int width, int height)
Create a fixed size thumbnail.
public Thumbnailer thumbSquare(int size)
Create a square thumbnail.
public Thumbnailer thumbSymmetric(int width, int height)
Creates scaled thumbnail of maximum width $width and maximum height $height.
public Thumbnailer thumbSymmetricHeight(int height)
Create a thumbnail with fixed height and scaled width.
public Thumbnailer thumbSymmetricWidth(int width)
Create a thumbnail with fixed width and scaled height.
public static mixed upload(string fieldName, callback callback)
Upload helper. Example usage:
function callb(Thumbnailer $th) {
return $th->round()->save('/save/path/'.$th->randonName());
}echo Thumbnailer::upload('file', 'callb');
Thumbnailer premium class.
Copyright (C) 2009/2011 by Michal Zukowski Permission is hereby granted, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction excluding the rights to copy, modify, merge, publish or distribute and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.