Return to the site!

API Methods

  • border
  • batch
  • colorHex
  • colorRGB
  • effectGray
  • getFilename
  • logoText
  • logoPhoto
  • round
  • save
  • setAllowed
  • setPrefix
  • setThumbName
  • setSaveLocation
  • thumbFixed
  • thumbSquare
  • thumbSymmetric
  • thumbSymmetricWidth
  • thumbSymmetricHeight
  • upload

API Fields

  • allowed
  • name
  • resource
  • thumb
  • thumb_width
  • thumb_height
  • savefunc
  • saveLocation
  • prefix
  • thumbName

API Exceptions

  • ThumbnailerException

List of API Methods

  • thumbFixed(int $width, int $height)

    Create thumb with fixed $width and $height.

    This method can be chained.

    back to top
  • thumbSquare(int $width)

    Create a square thumb $width wide, and $width tall.

    This method can be chained.

    back to top
  • thumbSymmetric(int $width)

    Creates a symmetric thumb with ratio keeped. It photo is wider, it will have maximum width of $width pixels. It photo is taller, it will have maximum height of $width pixels. It photo is square, thumbSquare method will be used automatically.

    This method can be chained.

    back to top
  • thumbSymmetricWidth(int $width)

    Generates a symmetric thumb of an image based on image width.

    This method can be chained.

    back to top
  • thumbSymmetricHeight(int $height)

    Generates a symmetric thumb of an image based on image height.

    This method can be chained.

    back to top
  • border(array $color)

    Create a border frame over the photo. Color should be an array of (int r, int g, int b). You can use static colorRGB() or colorHex() methods instead.

    This method can be chained.

    back to top
  • static batch(callback $func, string $in, string $out)

    Static batch mode helper. First parameter should be a name of the defined callback function. Second parameter is input mask. For more information about creating input masks please refer to php's glob function help at php.net/glob/. Last parameter is optional and if set, script will save generated thumbs automatically to that location, so there's no need to call the save() method.

    Example usage:

    function foo(& $thumb) {
    	$thumb->thumbSquare(50);
    }
    
    Thumbnailer::batch('foo', '/my/photos/*.jpg', '/my/photos/thumbs/');
    		
    back to top
  • static upload(string $fieldName, callback $func, string $out)

    Static upload helper. First parameter should be a name of the file field from $_FILES superglobal array. Second parameter is the callback function. Last parameter is optional and if set, script will save generated thumbs automatically to that location, so there's no need to call the save() method.

    Example usage:

    function foo(& $thumb) {
    	$thumb->thumbSquare(50)->save('/my/photo/thumbs/myThumb.jpg');
    }
    
    Thumbnailer::upload('myFile', 'foo');
    		
    back to top
  • static colorHex(string $color)

    Define color for some functions. $color should be a string like #FFFFFF or #123456.

    back to top
  • static colorRGB(array $color)

    Define color for some functions. $color should be an array of (int red, int blue, int green).

    back to top
  • effectGray()

    Turn thumb into grayscale.

    This method can be chained.

    back to top
  • getFilename()

    Gets source photo filename.

    back to top
  • logoText(string $text, int $x=10, int $y=20, $color, int $font=2)

    Puts $text based watermark on the thumb at $x px from the left side and $y px from the bottom.

    $color should be an array of (R,G,B) or use colorHex, colorRGB methods.

    $font can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) - php manual.

    This method can be chained.

    $thumb=new Thumbnailer('myPhoto.jpg');
    $thumb->thumbSymmetric(200)->logoText('my site.com')->save();
    		
    back to top
  • logoPhoto(string $photo, int $x=10, int $y=20, int $alpha=0)

    Puts $photo based watermark on the thumb at $x px from the left side and $y px from the bottom.

    Alpha should be between 0 and 100. Use it only with PNG images though.

    This method can be chained.

    $thumb=new Thumbnailer('myPhoto.jpg');
    $thumb->thumbSymmetric(200)->logoPhoto('/images/myPhoto.png')->save();
    		
    back to top
  • round($corners=all, $color=white, int $radius=5)

    Rounds corners of the thumb with $radius px size. It is important to first do anything with the photo, ie. resize it. $corners should be one of:

    Thumbnailer::TOP_LEFT

    Thumbnailer::TOP_RIGHT

    Thumbnailer::BOTTOM_LEFT

    Thumbnailer::BOTTOM_RIGHT

    Thumbnailer::ROUND_ALL.

    You can also combine those variables using bit operator | i.e.:

    Thumbnailer::TOP_LEFT | Thumbnailer::BOTTOM_RIGHT

    $color should be an array of (R,G,B) or use colorHex, colorRGB methods.

    This method can be chained.

    $thumb=new Thumbnailer('myPhoto.jpg');
    $thumb->thumbSquare(80)->round(Thumbnailer::ROUND_ALL, Thumbnailer::colorHex('#FFFFFF'), 5);
    $thumb->save('thumb_myphoto.jpg');
    		
    back to top
  • save(string $file, int $quality)

    Save the thumb into specified file. Quality is optional (only for JPEG images) and should be between 1-100 (1 worst quality, 100 best quality).

    If $file is not set or is null, thumb will be flushed directly to the browser.

    back to top
  • static setAllowed(array $allowed)

    Change allowed mime types. Example usage:

    Thumbnailer::setAllowed(array('image/jpeg'));
    		
    back to top
  • static setPrefix(string $prefix)

    Set prefix for saved thumbs. Default is thumb_. It is used only in auto save mode.

    back to top
  • setThumbName(string $name)

    Set under what name thumb will be saved in auto save mode. I.e.: my_thumb.jpg

    back to top
  • static setSaveLocation(string $directory)

    Using this method will enable the auto save mode. Set under which directory files will be saved. No need to call save every time then.

    back to top
  • API Fields

    • static array $allowed

      Set this field to tell what kind of images will be accepted by the script. If photo does not match any element from the following array, ThumbnailerException will be thrown.

      For default script accepts only JPEG, GIF and PNG images, but you can change it:

      // only JPEG images allowed
      Thumbnailer::setAllowed(array('image/jpeg', 'image/jpg'));
      		
      back to top
    • string $name

      After the constructor is called, here will be photo's path kept.

      back to top
    • resource $resource

      After the constructor is called, here will be stored the original photo.

      back to top
    • resource $thumb

      Generated thumb's resource data

      back to top
    • int $thumb_width

      When you generate any thumb, you can access its width.

      back to top
    • int $thumb_height

      When you generate any thumb, you can access its height.

      back to top
    • string $savefunc

      You can change the saving function for the thumb manually.

      back to top
    • static string $saveLocation

      You can set the default saving location for generated thumbs so there's no need to call save() method every time.

      It can be accessed by two ways:

      // directly
      Thumbnailer::$saveLocation='/some/dir/';
      // or through the appropriate method
      Thumbnailer::setSaveLocation('/some/dir/');
      		
      back to top
    • string $prefix

      After setting the saveLocation field, thumbs will be saved into that location under default name of $prefix and original photo's filename, ie: prefix_myphoto.jpg. You can change that prefix or empty it.

      It can be accessed by two ways:

      // directly
      Thumbnailer::$prefix='myprefix_';
      // or through the appropriate method
      Thumbnailer::setPrefix('myprefix_');
      		
      back to top
    • string $thumbName

      If $saveLocation field is set (auto save mode) you can define under what name the generated thumb will be saved instead of the default name of prefix_filename.

      back to top

    API Exceptions

    • ThumbnailerException
© freelogic.pl/thumbnailer | last update August 19, 2009