Class Thumbnail

Description

Thumbnail and Watermark 1.48

This is a class that can process an image on the fly by either generate a thumbnail, apply an watermark to the image, or resize it.

The processed image can either be displayed in a page, saved to a file, or returned to a variable. It requires the PHP with support for GD library extension in either version 1 or 2. If the GD library version 2 is available it the class can manipulate the images in true color, thus providing better quality of the results of resized images. Features description:

  • Thumbnail: normal thumbnail generation
  • Watermark: Text or image in PNG format. Suport multiples positions.
  • Auto-fitting: adjust the dimensions so that the resized image aspect is not distorted
  • Scaling: enlarge and shrink the image
  • Format: both JPEG and PNG are supported, but the watermark image can only be in PNG format as it needs to be transparent
  • Autodetect the GD library version supported by PHP
  • Calculate quality factor for a specific file size in JPEG format.
  • Suport bicubic resample algorithm
  • Generate unique filenames
  • Tested: PHP 4 valid

  • copyright: GNU General Public License (GPL)
  • version: 1.48 <2005/07/18>
  • author: Emilio Rodriguez <mailto:[email protected]>

Located in /Thumbnail.class.php (line 69)


	
			
Variable Summary
Method Summary
boolean Thumbnail (string $imgfile)
void CalculateQFactor (integer $size)
mixed dump ()
void gdVersion (mixed $user_ver)
void imageCopyResampleBicubic (mixed $dst_img, mixed $src_img, mixed $dst_x, mixed $dst_y, mixed $src_x, mixed $src_y, mixed $dst_w, mixed $dst_h, mixed $src_w, mixed $src_h)
void imagemergealpha (mixed $i)
boolean process ()
boolean save ([string $save = ""])
void show ()
boolean size (integer $size_x, integer $size_y)
boolean size_auto ([integer $size = 100])
boolean size_height ([integer $size = 100])
boolean size_width ([integer $size = 100])
string unique_filename (string $archive_dir, string $filename, [string $file_prefix = ''])
Variables
boolean $allow_enlarge = false (line 89)
  • var: allow to enlarge the thumbnail.
  • access: public
bool $bicubic_resample = false (line 146)
  • var: [OPTIONAL] set resample algorithm to bicubic
  • access: public
string $error_msg = '' (line 164)
  • var: errors mensage
  • access: public
string $img_watermark = '' (line 95)
  • var: [OPTIONAL] set watermark source file, only PNG format [RECOMENDED ONLY WITH GD 2 ]
  • access: public
string $img_watermark_Haling = 'LEFT' (line 105)
  • var: [OPTIONAL] set watermark horizonatal position, LEFT | CENTER | RIGHT
  • access: public
string $img_watermark_Valing = 'TOP' (line 100)
  • var: [OPTIONAL] set watermark vertical position, TOP | CENTER | BOTTOM
  • access: public
integer $jpeg_progressive (line 84)
  • var: set JPEG output format to progressive JPEG : 0 = no , 1 = yes
  • access: public
string $max_execution_time = '30' (line 158)
  • var: [OPTIONAL] set maximun execution time, default 30 seconds ('30'). (use '60' for big images)
  • access: public
string $memory_limit = '32M' (line 152)
  • var: [OPTIONAL] set maximun memory usage, default 8 MB ('8M'). (use '16M' for big images)
  • access: public
string $output_format = 'JPG' (line 79)
  • var: output format, default JPG, valid values 'JPG' | 'PNG'
  • access: public
integer $quality = 75 (line 74)
  • var: Quality factor for JPEG output format, default 75
  • access: public
string $txt_watermark = '' (line 111)
  • var: [OPTIONAL] set watermark text [RECOMENDED ONLY WITH GD 2 ]
  • access: public
string $txt_watermark_color = '000000' (line 116)
  • var: [OPTIONAL] set watermark text color , RGB Hexadecimal[RECOMENDED ONLY WITH GD 2 ]
  • access: public
integer $txt_watermark_font = 1 (line 121)
  • var: [OPTIONAL] set watermark text font: 1,2,3,4,5
  • access: public
string $txt_watermark_Haling = 'LEFT' (line 131)
  • var: [OPTIONAL] set watermark text horizonatal position, LEFT | CENTER | RIGHT
  • access: public
integer $txt_watermark_Hmargin = 10 (line 136)
  • var: [OPTIONAL] set watermark text horizonatal margin in pixels
  • access: public
string $txt_watermark_Valing = 'TOP' (line 126)
  • var: [OPTIONAL] set watermark text vertical position, TOP | CENTER | BOTTOM
  • access: public
integer $txt_watermark_Vmargin = 10 (line 141)
  • var: [OPTIONAL] set watermark text vertical margin in pixels
  • access: public
Methods
Constructor Thumbnail (line 179)

open source image

  • access: public
boolean Thumbnail (string $imgfile)
  • string $imgfile: filename of the source image file
CalculateQFactor (line 410)

Calculate JPEG quality factor for a specific size in bytes

  • access: public
void CalculateQFactor (integer $size)
  • integer $size: maximun file size in bytes
dump (line 313)

return the result thumbnail

  • access: public
mixed dump ()
gdVersion (line 546)

Get which version of GD is installed, if any.

Returns the version (1 or 2) of the GD extension.

void gdVersion (mixed $user_ver)
imageCopyResampleBicubic (line 582)
void imageCopyResampleBicubic (mixed $dst_img, mixed $src_img, mixed $dst_x, mixed $dst_y, mixed $src_x, mixed $src_y, mixed $dst_w, mixed $dst_h, mixed $src_w, mixed $src_h)
imagemergealpha (line 676)

NOT USED : to do: mezclar imagenes a tamaņo original, preservar canal alpha y redimensionar

Merge multiple images and keep transparency $i is and array of the images to be merged: $i[1] will be overlayed over $i[0] $i[2] will be overlayed over that

void imagemergealpha (mixed $i)
  • mixed $i
process (line 344)

generate image

  • access: public
boolean process ()
save (line 324)

save your thumbnail to file

  • access: public
boolean save ([string $save = ""])
  • string $save: output file name
show (line 297)

show your thumbnail, output image and headers

  • access: public
void show ()
size (line 282)

set the biggest width and height for thumbnail

  • access: public
boolean size (integer $size_x, integer $size_y)
  • integer $size_x: width
  • integer $size_y: height
size_auto (line 265)

set the biggest width or height for thumbnail

  • access: public
boolean size_auto ([integer $size = 100])
  • integer $size: width or height
size_height (line 212)

set height for thumbnail

  • access: public
boolean size_height ([integer $size = 100])
  • integer $size: height
size_width (line 239)

set width for thumbnail

  • access: public
boolean size_width ([integer $size = 100])
  • integer $size: width
unique_filename (line 634)

generate a unique filename in a directory like prefix_filename_randon.ext

  • return: full path of the file to save. Exmaple '/img/picture_my_foto_94949.jpg'
  • access: public
string unique_filename (string $archive_dir, string $filename, [string $file_prefix = ''])
  • string $archive_dir: path of the destination dir. Example '/img'
  • string $filename: name of the file to save. Example 'my_foto.jpg'
  • string $file_prefix: [optional] prefix of the name Example 'picture'

Documentation generated on Mon, 18 Jul 2005 15:02:34 +0200 by phpDocumentor 1.2.3