Donations accepted

Hosted on verot.net

class.upload.php documentation

Description

What does it do?

It manages file uploads for you. In short, it manages the uploaded file, and allows you to do whatever you want with the file, especially if it is an image, and as many times as you want.

It is the ideal class to quickly integrate file upload in your site. If the file is an image, you can convert, resize, crop it in many ways. You can also apply filters, add borders, text, watermarks, etc... That's all you need for a gallery script for instance. Supported formats are PNG, JPG, GIF and BMP.

You can also use the class to work on local files, which is especially useful to use the image manipulation features. The class also supports Flash uploaders.

The class works with PHP 4 and 5, and its error messages can be localized at will.

How does it work?

You instanciate the class with the $_FILES['my_field'] array where my_field is the field name from your upload form. The class will check if the original file has been uploaded to its temporary location (alternatively, you can instanciate the class with a local filename).

You can then set a number of processing variables to act on the file. For instance, you can rename the file, and if it is an image, convert and resize it in many ways. You can also set what will the class do if the file already exists.

Then you call the function process to actually perform the actions according to the processing parameters you set above. It will create new instances of the original file, so the original file remains the same between each process. The file will be manipulated, and copied to the given location. The processing variables will be reset once it is done.

You can repeat setting up a new set of processing variables, and calling process again as many times as you want. When you have finished, you can call clean to delete the original uploaded file.

If you don't set any processing parameters and call process just after instanciating the class. The uploaded file will be simply copied to the given location without any alteration or checks.

Don't forget to add enctype="multipart/form-data" in your form tag <form> if you want your form to upload the file.

How to use it?
Create a simple HTML file, with a form such as:

 <form enctype="multipart/form-data" method="post" action="#">
   <input type="file" size="32" name="image_field" value="">
   <input type="submit" name="Submit" value="upload">
 </form>
Create a file called upload.php:
  $handle = new upload($_FILES['image_field']);
  if ($handle->uploaded) {
      $handle->file_new_name_body   = 'image_resized';
      $handle->image_resize         = true;
      $handle->image_x              = 100;
      $handle->image_ratio_y        = true;
      $handle->process('/home/user/files/');
      if ($handle->processed) {
          echo 'image resized';
          $handle->clean();
      } else {
          echo 'error : ' . $handle->error;
      }
  }

How to process a file uploaded via XMLHttpRequest?
Use the class as following, the rest being the same as above:

  $handle = new upload('php:'.$_SERVER['HTTP_X_FILE_NAME']);
Prefixing the argument with "php:" tells the class to retrieve the uploaded data in php://input, and the rest is the stream's filename, which is generally in $_SERVER['HTTP_X_FILE_NAME']. But you can use any other name you see fit:
  $handle = new upload('php:mycustomname.ext');

How to process local files?
Use the class as following, the rest being the same as above:

  $handle = new upload('/home/user/myfile.jpg');

How to set the language?
Instantiate the class with a second argument being the language code:

  $handle = new upload($_FILES['image_field'], 'fr_FR');
  $handle = new upload('/home/user/myfile.jpg', 'fr_FR');

How to output the resulting file or picture directly to the browser?
Simply call process() without an argument (or with null as first argument):

  $handle = new upload($_FILES['image_field']);
  header('Content-type: ' . $handle->file_src_mime);
  echo $handle->Process();
  die();
Or if you want to force the download of the file:
  $handle = new upload($_FILES['image_field']);
  header('Content-type: ' . $handle->file_src_mime);
  header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
  echo $handle->Process();
  die();

Processing parameters (reset after each process)

  • file_new_name_body replaces the name body (default: null)
    $handle->file_new_name_body = 'new name';
  • file_name_body_add appends to the name body (default: null)
    $handle->file_name_body_add = '_uploaded';
  • file_name_body_pre prepends to the name body (default: null)
    $handle->file_name_body_pre = 'thumb_';
  • file_new_name_ext replaces the file extension (default: null)
    $handle->file_new_name_ext = 'txt';
  • file_safe_name formats the filename (spaces changed to _) (default: true)
    $handle->file_safe_name = true;
  • file_force_extension forces an extension if there is't any (default: true)
    $handle->file_force_extension = true;
  • file_overwrite sets behaviour if file already exists (default: false)
    $handle->file_overwrite = true;
  • file_auto_rename automatically renames file if it already exists (default: true)
    $handle->file_auto_rename = true;
  • dir_auto_create automatically creates destination directory if missing (default: true)
    $handle->auto_create_dir = true;
  • dir_auto_chmod automatically attempts to chmod the destination directory if not writeable (default: true)
    $handle->dir_auto_chmod = true;
  • dir_chmod chmod used when creating directory or if directory not writeable (default: 0777)
    $handle->dir_chmod = 0777;
  • file_max_size sets maximum upload size (default: upload_max_filesize from php.ini)
    $handle->file_max_size = '1024'; // 1KB
  • mime_check sets if the class check the MIME against the allowed list (default: true)
    $handle->mime_check = true;
  • no_script sets if the class turns scripts into text files (default: true)
    $handle->no_script = false;
  • allowed array of allowed mime-types (or one string). wildcard accepted, as in image/* (default: check Init)
    $handle->allowed = array('application/pdf','application/msword', 'image/*');
  • forbidden array of forbidden mime-types (or one string). wildcard accepted, as in image/* (default: check Init)
    $handle->forbidden = array('application/*');
  • image_convert if set, image will be converted (possible values : ''|'png'|'jpeg'|'gif'|'bmp'; default: '')
    $handle->image_convert = 'jpg';
  • image_background_color if set, will forcibly fill transparent areas with the color, in hexadecimal (default: null)
    $handle->image_background_color = '#FF00FF';
  • image_default_color fallback color background color for non alpha-transparent output formats, such as JPEG or BMP, in hexadecimal (default: #FFFFFF)
    $handle->image_default_color = '#FF00FF';
  • png_compression sets the compression level for PNG images, between 1 (fast but large files) and 9 (slow but smaller files) (default: null (Zlib default))
    $handle->png_compression = 9;
  • jpeg_quality sets the compression quality for JPEG images (default: 85)
    $handle->jpeg_quality = 50;
  • jpeg_size if set to a size in bytes, will approximate jpeg_quality so the output image fits within the size (default: null)
    $handle->jpeg_size = 3072;
  • image_interlace if set to true, the image will be saved interlaced (default: false)
    $handle->image_interlace = true;
The following eight settings can be used to invalidate an upload if the file is an image (note that open_basedir restrictions prevent the use of these settings)
  • image_max_width if set to a dimension in pixels, the upload will be invalid if the image width is greater (default: null)
    $handle->image_max_width = 200;
  • image_max_height if set to a dimension in pixels, the upload will be invalid if the image height is greater (default: null)
    $handle->image_max_height = 100;
  • image_max_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is greater (default: null)
    $handle->image_max_pixels = 50000;
  • image_max_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is greater (default: null)
    $handle->image_max_ratio = 1.5;
  • image_min_width if set to a dimension in pixels, the upload will be invalid if the image width is lower (default: null)
    $handle->image_min_width = 100;
  • image_min_height if set to a dimension in pixels, the upload will be invalid if the image height is lower (default: null)
    $handle->image_min_height = 500;
  • image_min_pixels if set to a number of pixels, the upload will be invalid if the image number of pixels is lower (default: null)
    $handle->image_min_pixels = 20000;
  • image_min_ratio if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is lower (default: null)
    $handle->image_min_ratio = 0.5;
  • image_resize determines is an image will be resized (default: false)
    $handle->image_resize = true;
The following variables are used only if image_resize == true
  • image_x destination image width (default: 150)
    $handle->image_x = 100;
  • image_y destination image height (default: 150)
    $handle->image_y = 200;
Use either one of the following
  • image_ratio if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes if true (default: false)
    $handle->image_ratio = true;
  • image_ratio_crop if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes, and cropping excedent to fill the space. setting can also be a string, with one or more from 'TBLR', indicating which side of the image will be kept while cropping (default: false)
    $handle->image_ratio_crop = true;
  • image_ratio_fill if true, resize image conserving the original sizes ratio, using image_x AND image_y as max sizes, fitting the image in the space and coloring the remaining space. setting can also be a string, with one or more from 'TBLR', indicating which side of the space the image will be in (default: false)
    $handle->image_ratio_fill = true;
  • image_ratio_no_zoom_in same as image_ratio, but won't resize if the source image is smaller than image_x x image_y (default: false)
    $handle->image_ratio_no_zoom_in = true;
  • image_ratio_no_zoom_out same as image_ratio, but won't resize if the source image is bigger than image_x x image_y (default: false)
    $handle->image_ratio_no_zoom_out = true;
  • image_ratio_x if true, resize image, calculating image_x from image_y and conserving the original sizes ratio (default: false)
    $handle->image_ratio_x = true;
  • image_ratio_y if true, resize image, calculating image_y from image_x and conserving the original sizes ratio (default: false)
    $handle->image_ratio_y = true;
  • image_ratio_pixels if set to a long integer, resize image, calculating image_y and image_x to match a the number of pixels (default: false)
    $handle->image_ratio_pixels = 25000;
The following image manipulations require GD2+
  • image_brightness if set, corrects the brightness. value between -127 and 127 (default: null)
    $handle->image_brightness = 40;
  • image_contrast if set, corrects the contrast. value between -127 and 127 (default: null)
    $handle->image_contrast = 50;
  • image_opacity if set, changes the image opacity. value between 0 and 100 (default: null)
    $handle->image_opacity = 50;
  • image_tint_color if set, will tint the image with a color, value as hexadecimal #FFFFFF (default: null)
    $handle->image_tint_color = '#FF0000';
  • image_overlay_color if set, will add a colored overlay, value as hexadecimal #FFFFFF (default: null)
    $handle->image_overlay_color = '#FF0000';
  • image_overlay_opacity used when image_overlay_color is set, determines the opacity (default: 50)
    $handle->image_overlay_opacity = 20;
  • image_negative inverts the colors in the image (default: false)
    $handle->image_negative = true;
  • image_greyscale transforms an image into greyscale (default: false)
    $handle->image_greyscale = true;
  • image_threshold applies a threshold filter. value between -127 and 127 (default: null)
    $handle->image_threshold = 20;
  • image_pixelate pixelate an image, value is block size (default: null)
    $handle->image_pixelate = 10;
  • image_unsharp applies an unsharp mask, with alpha transparency support (default: false)
    $handle->image_unsharp = true;
  • image_unsharp_amount unsharp mask amount, typically 50 - 200 (default: 80)
    $handle->image_unsharp_amount = 120;
  • image_unsharp_radius unsharp mask radius, typically 0.5 - 1 (default: 0.5)
    $handle->image_unsharp_radius = 1;
  • image_unsharp_threshold unsharp mask threshold, typically 0 - 5 (default: 1)
    $handle->image_unsharp_threshold = 0;
  • image_text creates a text label on the image, value is a string, with eventual replacement tokens (default: null)
    $handle->image_text = 'test';
  • image_text_direction text label direction, either 'h' horizontal or 'v' vertical (default: 'h')
    $handle->image_text_direction = 'v';
  • image_text_color text color for the text label, in hexadecimal (default: #FFFFFF)
    $handle->image_text_color = '#FF0000';
  • image_text_opacity text opacity on the text label, integer between 0 and 100 (default: 100)
    $handle->image_text_opacity = 50;
  • image_text_background text label background color, in hexadecimal (default: null)
    $handle->image_text_background = '#FFFFFF';
  • image_text_background_opacity text label background opacity, integer between 0 and 100 (default: 100)
    $handle->image_text_background_opacity = 50;
  • image_text_font built-in font for the text label, from 1 to 5. 1 is the smallest (default: 5)
    $handle->image_text_font = 4;
  • image_text_x absolute text label position, in pixels from the left border. can be negative (default: null)
    $handle->image_text_x = 5;
  • image_text_y absolute text label position, in pixels from the top border. can be negative (default: null)
    $handle->image_text_y = 5;
  • image_text_position text label position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)
    $handle->image_text_position = 'LR';
  • image_text_padding text label padding, in pixels. can be overridden by image_text_padding_x and image_text_padding_y (default: 0)
    $handle->image_text_padding = 5;
  • image_text_padding_x text label horizontal padding (default: null)
    $handle->image_text_padding_x = 2;
  • image_text_padding_y text label vertical padding (default: null)
    $handle->image_text_padding_y = 10;
  • image_text_alignment text alignment when text has multiple lines, either 'L', 'C' or 'R' (default: 'C')
    $handle->image_text_alignment = 'R';
  • image_text_line_spacing space between lines in pixels, when text has multiple lines (default: 0)
    $handle->image_text_line_spacing = 3;
  • image_flip flips image, wither 'h' horizontal or 'v' vertical (default: null)
    $handle->image_flip = 'h';
  • image_rotate rotates image. possible values are 90, 180 and 270 (default: null)
    $handle->image_rotate = 90;
  • image_crop crops image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)
    $handle->image_crop = array(50,40,30,20); OR '-20 20%'...
  • image_precrop crops image, before an eventual resizing. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)
    $handle->image_precrop = array(50,40,30,20); OR '-20 20%'...
  • image_bevel adds a bevel border to the image. value is thickness in pixels (default: null)
    $handle->image_bevel = 20;
  • image_bevel_color1 top and left bevel color, in hexadecimal (default: #FFFFFF)
    $handle->image_bevel_color1 = '#FFFFFF';
  • image_bevel_color2 bottom and right bevel color, in hexadecimal (default: #000000)
    $handle->image_bevel_color2 = '#000000';
  • image_border adds a unicolor border to the image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)
    $handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...
  • image_border_color border color, in hexadecimal (default: #FFFFFF)
    $handle->image_border_color = '#FFFFFF';
  • image_border_opacity border opacity, integer between 0 and 100 (default: 100)
    $handle->image_border_opacity = 50;
  • image_border_transparent adds a fading-to-transparent border to the image. accepts 4, 2 or 1 values as 'T R B L' or 'TB LR' or 'TBLR'. dimension can be 20, or 20px or 20% (default: null)
    $handle->image_border_transparent = '3px'; OR '-20 20%' OR array(3,2)...
  • image_frame type of frame: 1=flat 2=crossed (default: null)
    $handle->image_frame = 2;
  • image_frame_colors list of hex colors, in an array or a space separated string (default: '#FFFFFF #999999 #666666 #000000')
    $handle->image_frame_colors = array('#999999',  '#FF0000', '#666666', '#333333', '#000000');
  • image_frame_opacity frame opacity, integer between 0 and 100 (default: 100)
    $handle->image_frame_opacity = 50;
  • image_watermark adds a watermark on the image, value is a local filename. accepted files are GIF, JPG, BMP, PNG and PNG alpha (default: null)
    $handle->image_watermark = 'watermark.png';
  • image_watermark_x absolute watermark position, in pixels from the left border. can be negative (default: null)
    $handle->image_watermark_x = 5;
  • image_watermark_y absolute watermark position, in pixels from the top border. can be negative (default: null)
    $handle->image_watermark_y = 5;
  • image_watermark_position watermark position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)
    $handle->image_watermark_position = 'LR';
  • image_watermark_no_zoom_in prevents the watermark to be resized up if it is smaller than the image (default: true)
    $handle->image_watermark_no_zoom_in = false;
  • image_watermark_no_zoom_out prevents the watermark to be resized down if it is bigger than the image (default: false)
    $handle->image_watermark_no_zoom_out = true;
  • image_reflection_height if set, a reflection will be added. Format is either in pixels or percentage, such as 40, '40', '40px' or '40%' (default: null)
    $handle->image_reflection_height = '25%';
  • image_reflection_space space in pixels between the source image and the reflection, can be negative (default: null)
    $handle->image_reflection_space = 3;
  • image_reflection_color reflection background color, in hexadecimal. Now deprecated in favor of image_default_color (default: #FFFFFF)
    $handle->image_default_color = '#000000';
  • image_reflection_opacity opacity level at which the reflection starts, integer between 0 and 100 (default: 60)
    $handle->image_reflection_opacity = 60;

Values that can be read before calling process()

If the file is a supported image type (and open_basedir restrictions allow it)

Values that can be read after calling process()

If the file is a supported image type

Requirements

Most of the image operations require GD. GD2 is greatly recommended

The class requires PHP 4.3+, and is compatible with PHP5

Changelog

  • v 0.32 15/01/2013
    - add support for XMLHttpRequest uploads
    - added image_pixelate
    - added image_interlace
    - added png_compression to change PNG compressoin level
    - deactivate exec() if Suhosin is enabled
    - add more extension to dangerous scripts detection
    - imagejpeg takes null as second argument since PHP 5.4
    - default PECL Fileinfo MAGIC path to null
    - set gd.jpeg_ignore_warning to true by default
    - fixed file name normalization
  • v 0.31 11/04/2011
    - added application/x-rar MIME type
    - make sure exec() and ini_get_all()function are not disabled if we want to use them
    - make sure that we don't divide by zero when calculating JPEG size
    - allowed and forbidden can now accept strings
    - try to guess the file extension from the MIME type if there is no file extension
    - better class properties when changing the file extension
    - added file_force_extension to allow extension-less files if needed
    - better file safe conversion of the filename
    - allow shorthand byte values, such as 1K, 2M, 3G for file_max_size and jpeg_size
    - added image_opacity to change picture opacity
    - added image_border_opacity to allow semi-transparent borders
    - added image_frame_opacity to allow semi-transparent frames
    - added image_border_transparent to allow borders fading to transparent
    - duplicated image_overlay_percent into image_overlay_opacity
    - duplicated image_text_percent into image_text_opacity
    - duplicated image_text_background_percent into image_text_background_opacity
  • v 0.30 05/09/2010
    - implemented an unsharp mask, with alpha transparency support, activated if image_unsharp is true. added image_unsharp_amount, image_unsharp_radius, and image_unsharp_threshold
    - added text/rtf MIME type, and no_script exception
    - corrected bug when no_script is activated and several process() are called
    - better error handling for finfo
    - display upload_max_filesize information from php.ini in the log
    - automatic extension for extension-less images
    - fixed image_ratio_fill top and left filling
    - fixed alphablending issue when applying a transparent PNG watermark on a transparent PNG
    - added image_watermark_no_zoom_in and image_watermark_no_zoom_out to allow the watermark to be resized down (or up) to fit in the image. By default, the watermark may be resized down, but not up.
  • v 0.29 03/02/2010
    - added protection against malicious images
    - added zip and torrent MIME type
    - replaced split() with explode()
    - initialise image_dst_x/y with image_src_x/y
    - removed mime_fileinfo, mime_file, mime_magic and mime_getimagesize from the docs since they are used before process
    - added more extensions and MIME types
    - improved MIME type validation
    - improved logging
  • v 0.28 10/08/2009
    - replaced ereg functions to be compatible with PHP 5.3
    - added flv MIME type
    - improved MIME type detection
    - added file_name_body_pre to prepend a string to the file name
    - added mime_fileinfo, mime_file, mime_magic and mime_getimagesize so that it is possible to deactivate some MIME type checking method
    - use exec() rather than shell_exec(), to play better with safe mode
    - added some error messages
    - fix bug when checking on conditions, processed wasn't propagated properly
  • v 0.27 14/05/2009
    - look for the language files directory from __FILE__
    - deactivate file_auto_rename if file_overwrite is set
    - improved transparency replacement for true color images
    - fixed calls to newer version of UNIX file utility
    - fixed error when using PECL Fileinfo extension in SAFE MODE, and when using the finfo class
    - added image_precrop to crop the image before an eventual resizing
  • v 0.26 13/11/2008
    - rewrote conversion from palette to true color to handle transparency better
    - fixed imagecopymergealpha() when the overlayed image is of wrong dimensions
    - fixed imagecreatenew() when the image to create have less than 1 pixels width or height
    - rewrote MIME type detection to be more secure and not rely on browser information; now using Fileinfo PECL extension, UNIX file() command, MIME magic, and getimagesize(), in that order
    - added support for Flash uploaders
    - some bug fixing and error handling
  • v 0.25 17/11/2007
    - added translation files and mechanism to instantiate the class with a language different from English
    - added forbidden to set an array of forbidden MIME types
    - implemented support for simple wildcards in allowed and forbidden, such as image/*
    - preset the file extension to the desired conversion format when converting an image
    - added read and write support for BMP images
    - added a flag file_is_image to determine if the file is a supported image type
    - the class now provides some information about the image, before calling process(). Available are image_src_x, image_src_y and the newly introduced image_src_bits, image_src_pixels and image_src_type. Note that this will not work if open_basedir restrictions are in place
    - improved logging; now provides useful system information
    - added some more pre-processing checks for files that are images: image_max_width, image_max_height, image_max_pixels, image_max_ratio, image_min_width, image_min_height, image_min_pixels and image_min_ratio
    - added image_ratio_pixels to resize an image to a number of pixels, keeping aspect ratio
    - added image_is_palette and image_is_transparent and image_transparent_color for GIF images
    - added image_default_color to define a fallback color for non alpha-transparent output formats, such as JPEG or BMP
    - changed image_background_color, which now forces transparent areas to be painted
    - improved reflections and color overlays so that it works with alpha transparent images
    - image_reflection_color is now deprecated in favour of image_default_color
    - transparent PNGs are now processed in true color, and fully preserving the alpha channel when doing merges
    - transparent GIFs are now automatically detected. preserve_transparency is deprecated
    - transparent true color images can be saved as GIF while retaining transparency, semi transparent areas being merged with image_default_color
    - transparent true color images can be saved as JPG/BMP with the semi transparent areas being merged with image_default_color
    - fixed conversion of images to true color
    - the class can now output the uploaded files content as the return value of process() if the function is called with an empty or null argumenti, or no argument
  • v 0.24 25/05/2007
    - added image_background_color, to set the default background color of an image
    - added possibility of using replacement tokens in text labels
    - changed default JPEG quality to 85
    - fixed a small bug when using greyscale filter and associated filters
    - added image_ratio_fill in order to fit an image within some dimensions and color the remaining space. Very similar to image_ratio_crop
    - improved the recursive creation of directories
    - the class now converts palette based images to true colors before doing graphic manipulations
  • v 0.23 23/12/2006
    - fixed a bug when processing more than once the same uploaded file. If there is an open_basedir restriction, the class now creates a temporary file for the first call to process(). This file will be used for subsequent processes, and will be deleted upon calling clean()
  • v 0.22 16/12/2006
    - added automatic creation of a temporary file if the upload directory is not within open_basedir
    - fixed a bug which was preventing to work on a local file by overwriting it with its processed copy
    - added MIME types video/x-ms-wmv and image/x-png and fixed PNG support for IE weird MIME types
    - modified image_ratio_crop so it can accept one or more from string 'TBLR', determining which side of the image is kept while cropping
    - added support for multiple lines in the text, using "\n" as a line break
    - added image_text_line_spacing which allow to set the space between several lines of text
    - added image_text_alignment which allow to set the alignment when text has several lines
    - image_text_font can now be set to the path of a GDF font to load external fonts
    - added image_reflection_height to create a reflection of the source image, which height is in pixels or percentage
    - added image_reflection_space to set the space in pixels between the source image and the reflection
    - added image_reflection_color to set the reflection background color
    - added image_reflection_opacity to set the initial level of opacity of the reflection
  • v 0.21 30/09/2006
    - added image_ratio_crop which resizes within image_x and image_y, keeping ratio, but filling the space by cropping excedent of image
    - added mime_check, which default is true, to set checks against allowed MIME list
    - if MIME is empty, the class now triggers an error
    - color #000000 is OK for image_text_color, and related text transparency bug fixed
    - gd_version() now uses gd_info(), or else phpinfo()
    - fixed path issue when the destination path has no trailing slash on Windows systems
    - removed inline functions to be fully PHP5 compatible
  • v 0.20 11/08/2006
    - added some more error checking and messages (GD presence, permissions...)
    - fix when uploading files without extension
    - changed values for image_brightness and image_contrast to be between -127 and 127
    - added dir_auto_create to automatically and recursively create destination directory if missing.
    - added dir_auto_chmod to automatically chmod the destination directory if not writeable.
    - added dir_chmod to set the default chmod to use.
    - added image_crop to crop images
    - added image_negative to invert the colors on the image
    - added image_greyscale to turn the image into greyscale
    - added image_threshold to apply a threshold filter on the image
    - added image_bevel, image_bevel_color1 and image_bevel_color2 to add a bevel border
    - added image_border and image_border_color to add a single color border
    - added image_frame and image_frame_colors to add a multicolored frame
  • v 0.19 29/03/2006
    - class is now compatible i18n (thanks Sylwester).
    - the class can mow manipulate local files, not only uploaded files (instanciate the class with a local filename).
    - file_safe_name has been improved a bit.
    - added image_brightness, image_contrast, image_tint_color, image_overlay_color and image_overlay_percent to do color manipulation on the images.
    - added image_text and all derivated settings to add a text label on the image.
    - added image_watermark and all derivated settings to add a watermark image on the image.
    - added image_flip and image_rotate for more image manipulations
    - added jpeg_size to calculate the JPG compression quality in order to fit within one filesize.
  • v 0.18 02/02/2006
    - added no_script to turn dangerous scripts into text files.
    - added mime_magic_check to set the class to use mime_magic.
    - added preserve_transparency *experimental*. Thanks Gregor.
    - fixed size and mime checking, wasn't working :/ Thanks Willem.
    - fixed memory leak when resizing images.
    - when resizing, it is not necessary anymore to set image_convert.
    - il is now possible to simply convert an image, with no resizing.
    - sets the default file_max_size to upload_max_filesize from php.ini. Thanks Edward
  • v 0.17 28/05/2005
    - the class can be used with any version of GD.
    - added security check on the file with a list of mime-types.
    - changed the license to GPL v2 only
  • v 0.16 19/05/2005
    - added file_auto_rename automatic file renaming if the same filename already exists.
    - added file_safe_name safe formatting of the filename (spaces to _underscores so far).
    - added some more error reporting to avoid crash if GD is not present
  • v 0.15 16/04/2005
    - added JPEG compression quality setting. Thanks Vad
  • v 0.14 14/03/2005
    - reworked the class file to allow parsing with phpDocumentor
  • v 0.13 07/03/2005
    - fixed a bug with image_ratio. Thanks Justin.
    - added image_ratio_no_zoom_in and image_ratio_no_zoom_out
  • v 0.12 21/01/2005
    - added image_ratio to resize within max values, keeping image ratio
  • v 0.11 22/08/2003
    - update for GD2 (changed imageresized() into imagecopyresampled() and imagecreate() into imagecreatetruecolor())


	
			
Variable Summary
 array $allowed
 bool $dir_chmod
 string $error
 boolean $file_is_image
 boolean $file_safe_name
 array $forbidden
 integer $image_bevel
 integer $image_border
 integer $image_contrast
 string $image_crop
 integer $image_dst_x
 integer $image_dst_y
 string; $image_flip
 integer $image_frame
 boolean; $image_greyscale
 boolean; $image_negative
 integer $image_opacity
 integer; $image_pixelate
 string; $image_rotate
 integer $image_src_bits
 integer $image_src_x
 integer $image_src_y
 string; $image_text
 integer $image_text_x
 integer $image_text_y
 boolean; $image_unsharp
 integer $image_x
 integer $image_y
 integer $jpeg_quality
 integer $jpeg_size
 array $language
 string $log
 boolean $mime_check
 boolean $mime_file
 boolean $mime_fileinfo
 boolean $mime_magic
 boolean $no_script
 bool $processed
 array $translation
 bool $uploaded
 string $version
Method Summary
 void clean ()
 float gdversion ([boolean $full = false])
 void imagebmp ( &$im, [ $filename = ""])
 void imagecreatefrombmp ( $filename)
 string process ([string $server_path = null])
Variables
array $allowed

Allowed MIME types

Default is a selection of safe mime-types, but you might want to change it

Simple wildcards are allowed, such as image/* or application/* If there is only one MIME type allowed, then it can be a string instead of an array

  • var: OR string
  • access: public
bool $dir_auto_chmod

Set this variable to true to allow automatic chmod of the destination directory if it is not writeable

Default value is true

  • access: public
bool $dir_auto_create

Set this variable to true to allow automatic creation of the destination directory if it is missing (works recursively)

Default value is true

  • access: public
bool $dir_chmod

Set this variable to the default chmod you want the class to use when creating directories, or attempting to write in a directory

Default value is 0777 (without quotes)

  • access: public
string $error

Holds eventual error message in plain english

  • access: public
bool $file_auto_rename

Set this variable to true to allow automatic renaming of the file if the file already exists

Default value is true

For instance, on uploading foo.ext,
if foo.ext already exists, upload will be renamed foo_1.ext
and if foo_1.ext already exists, upload will be renamed foo_2.ext

Note that this option doesn't have any effect if file_overwrite is true

  • access: public
string $file_dst_name

Destination file name

  • access: public
string $file_dst_name_body

Destination file name body (i.e. without extension)

  • access: public
string $file_dst_name_ext

Destination file extension

  • access: public
string $file_dst_path

Destination file name

  • access: public
string $file_dst_pathname

Destination file name, including path

  • access: public
boolean $file_force_extension

Forces an extension if the source file doesn't have one

If the file is an image, then the correct extension will be added Otherwise, a .txt extension will be chosen

  • access: public
boolean $file_is_image

Flag to determine if the source file is an image

  • access: public
double $file_max_size

Set this variable to change the maximum size in bytes for an uploaded file

Default value is the value upload_max_filesize from php.ini

Value in bytes (integer) or shorthand byte values (string) is allowed. The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes)

  • access: public
string $file_name_body_add

Set this variable to append a string to the file name body

  • access: public
string $file_name_body_pre

Set this variable to prepend a string to the file name body

  • access: public
string $file_new_name_body

Set this variable to replace the name body (i.e. without extension)

  • access: public
string $file_new_name_ext

Set this variable to change the file extension

  • access: public
bool $file_overwrite

Set this variable tu true to allow overwriting of an existing file

Default value is false, so no files will be overwritten

  • access: public
boolean $file_safe_name

Set this variable to format the filename (spaces changed to _)

  • access: public
string $file_src_error

Holds eventual PHP error code from $_FILES

  • access: public
string $file_src_mime

Uploaded file MIME type

  • access: public
string $file_src_name

Uploaded file name

  • access: public
string $file_src_name_body

Uploaded file name body (i.e. without extension)

  • access: public
string $file_src_name_ext

Uploaded file name extension

  • access: public
string $file_src_pathname

Uloaded file name, including server path

  • access: public
double $file_src_size

Uploaded file size, in bytes

  • access: public
array $forbidden

Forbidden MIME types

Default is a selection of safe mime-types, but you might want to change it To only check for forbidden MIME types, and allow everything else, set allowed to array('* / *') without the spaces

Simple wildcards are allowed, such as image/* or application/* If there is only one MIME type forbidden, then it can be a string instead of an array

  • var: OR string
  • access: public
string $image_background_color

Background color, used to paint transparent areas with

If set, it will forcibly remove transparency by painting transparent areas with the color This setting will fill in all transparent areas in PNG and GIF, as opposed to image_default_color which will do so only in BMP, JPEG, and alpha transparent areas in transparent GIFs This setting overrides image_default_color

Default value is null

  • access: public
integer $image_bevel

Adds a bevel border on the image

Value is a positive integer, representing the thickness of the bevel

If the bevel colors are the same as the background, it makes a fade out effect

Default value is null (no bevel)

  • access: public
string; $image_bevel_color1

Top and left bevel color

Value is a color, in hexadecimal format This setting is used only if image_bevel is set

Default value is #FFFFFF

  • access: public
string; $image_bevel_color2

Right and bottom bevel color

Value is a color, in hexadecimal format This setting is used only if image_bevel is set

Default value is #000000

  • access: public
integer $image_border

Adds a single-color border on the outer of the image

Values are four dimensions, or two, or one (CSS style) They represent the border thickness top, right, bottom and left. These values can either be in an array, or a space separated string. Each value can be in pixels (with or without 'px'), or percentage (of the source image)

See image_crop for valid formats

If a value is negative, the image will be cropped. Note that the dimensions of the picture will be increased by the borders' thickness

Default value is null (no border)

  • access: public
string; $image_border_color

Border color

Value is a color, in hexadecimal format. This setting is used only if image_border is set

Default value is #FFFFFF

  • access: public
integer $image_border_opacity

Sets the opacity for the borders

Value is a percentage, as an integer between 0 (transparent) and 100 (opaque)

Unless used with image_border, this setting has no effect

Default value is 100

  • access: public
integer $image_border_transparent

Adds a fading-to-transparent border on the image

Values are four dimensions, or two, or one (CSS style) They represent the border thickness top, right, bottom and left. These values can either be in an array, or a space separated string. Each value can be in pixels (with or without 'px'), or percentage (of the source image)

See image_crop for valid formats

Note that the dimensions of the picture will not be increased by the borders' thickness

Default value is null (no border)

  • access: public
integer $image_brightness

Corrects the image brightness

Value can range between -127 and 127

Default value is null

  • access: public
integer $image_contrast

Corrects the image contrast

Value can range between -127 and 127

Default value is null

  • access: public
string $image_convert

Set this variable to convert the file if it is an image

Possibles values are : ''; 'png'; 'jpeg'; 'gif'; 'bmp'

Default value is '' (no conversion)
If resize is true, convert will be set to the source file extension

  • access: public
string $image_crop

Crops an image

Values are four dimensions, or two, or one (CSS style) They represent the amount cropped top, right, bottom and left. These values can either be in an array, or a space separated string. Each value can be in pixels (with or without 'px'), or percentage (of the source image)

For instance, are valid:

 $foo->image_crop = 20                  OR array(20);
 $foo->image_crop = '20px'              OR array('20px');
 $foo->image_crop = '20 40'             OR array('20', 40);
 $foo->image_crop = '-20 25%'           OR array(-20, '25%');
 $foo->image_crop = '20px 25%'          OR array('20px', '25%');
 $foo->image_crop = '20% 25%'           OR array('20%', '25%');
 $foo->image_crop = '20% 25% 10% 30%'   OR array('20%', '25%', '10%', '30%');
 $foo->image_crop = '20px 25px 2px 2px' OR array('20px', '25%px', '2px', '2px');
 $foo->image_crop = '20 25% 40px 10%'   OR array(20, '25%', '40px', '10%');

If a value is negative, the image will be expanded, and the extra parts will be filled with black

Default value is null (no cropping)

  • var: OR array;
  • access: public
boolean $image_default_color

Default color for non alpha-transparent images

This setting is to be used to define a background color for semi transparent areas of an alpha transparent when the output format doesn't support alpha transparency This is useful when, from an alpha transparent PNG image, or an image with alpha transparent features if you want to output it as a transparent GIFs for instance, you can set a blending color for transparent areas If you output in JPEG or BMP, this color will be used to fill in the previously transparent areas

The default color white

  • access: public
integer $image_dst_x

Destination image width

  • access: public
integer $image_dst_y

Destination image height

  • access: public
string; $image_flip

Flips the image vertically or horizontally

Value is either 'h' or 'v', as in horizontal and vertical

Default value is null (no flip)

  • access: public
integer $image_frame

Adds a multi-color frame on the outer of the image

Value is an integer. Two values are possible for now:

  1. for flat border, meaning that the frame is mirrored horizontally and vertically
  2. for crossed border, meaning that the frame will be inversed, as in a bevel effect
The frame will be composed of colored lines set in image_frame_colors

Note that the dimensions of the picture will be increased by the borders' thickness

Default value is null (no frame)

  • access: public
string $image_frame_colors

Sets the colors used to draw a frame

Values is a list of n colors in hexadecimal format. These values can either be in an array, or a space separated string.

The colors are listed in the following order: from the outset of the image to its center

For instance, are valid:

 $foo->image_frame_colors = '#FFFFFF #999999 #666666 #000000';
 $foo->image_frame_colors = array('#FFFFFF', '#999999', '#666666', '#000000');

This setting is used only if image_frame is set

Default value is '#FFFFFF #999999 #666666 #000000'

  • var: OR array;
  • access: public
integer $image_frame_opacity

Sets the opacity for the frame

Value is a percentage, as an integer between 0 (transparent) and 100 (opaque)

Unless used with image_frame, this setting has no effect

Default value is 100

  • access: public
boolean; $image_greyscale

Turns the image into greyscale

Default value is FALSE

  • access: public
boolean $image_interlace

Turns the interlace bit on

This is actually used only for JPEG images, and defaults to false

  • access: public
boolean $image_is_palette

Flag set to true when the image is not true color

  • access: public
boolean $image_is_transparent

Flag set to true when the image is transparent

This is actually used only for transparent GIFs

  • access: public
integer $image_max_height

Set this variable to set a maximum image height, above which the upload will be invalid

Default value is null

  • access: public
long $image_max_pixels

Set this variable to set a maximum number of pixels for an image, above which the upload will be invalid

Default value is null

  • access: public
float $image_max_ratio

Set this variable to set a maximum image aspect ratio, above which the upload will be invalid

Note that ratio = width / height

Default value is null

  • access: public
integer $image_max_width

Set this variable to set a maximum image width, above which the upload will be invalid

Default value is null

  • access: public
integer $image_min_height

Set this variable to set a minimum image height, below which the upload will be invalid

Default value is null

  • access: public
long $image_min_pixels

Set this variable to set a minimum number of pixels for an image, below which the upload will be invalid

Default value is null

  • access: public
float $image_min_ratio

Set this variable to set a minimum image aspect ratio, below which the upload will be invalid

Note that ratio = width / height

Default value is null

  • access: public
integer $image_min_width

Set this variable to set a minimum image width, below which the upload will be invalid

Default value is null

  • access: public
boolean; $image_negative

Inverts the color of an image

Default value is FALSE

  • access: public
integer $image_opacity

Changes the image opacity

Value can range between 0 and 100

Default value is null

  • access: public
string; $image_overlay_color

Applies a colored overlay on the image

Value is an hexadecimal color, such as #FFFFFF

To use with image_overlay_opacity

Default value is null

  • access: public
integer $image_overlay_opacity

Sets the opacity for the colored overlay

Value is a percentage, as an integer between 0 (transparent) and 100 (opaque)

Unless used with image_overlay_color, this setting has no effect

Default value is 50

  • access: public
integer $image_overlay_percent

Soon to be deprecated old form of image_overlay_opacity

  • access: public
integer; $image_pixelate

Pixelate an image

Value is integer, represents the block size

Default value is null

  • access: public
string $image_precrop

Crops an image, before an eventual resizing

See image_crop for valid formats

Default value is null (no cropping)

  • var: OR array;
  • access: public
bool $image_ratio

Set this variable to keep the original size ratio to fit within image_x x image_y

Default value is false

  • access: public
mixed $image_ratio_crop

Set this variable to keep the original size ratio to fit within image_x x image_y

The image will be resized as to fill the whole space, and excedent will be cropped

Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) If set as a string, it determines which side of the image is kept while cropping. By default, the part of the image kept is in the center, i.e. it crops equally on both sides

Default value is false

  • access: public
mixed $image_ratio_fill

Set this variable to keep the original size ratio to fit within image_x x image_y

The image will be resized to fit entirely in the space, and the rest will be colored. The default color is white, but can be set with image_default_color

Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right) If set as a string, it determines in which side of the space the image is displayed. By default, the image is displayed in the center, i.e. it fills the remaining space equally on both sides

Default value is false

  • access: public
bool $image_ratio_no_zoom_in

Set this variable to keep the original size ratio to fit within image_x x image_y, but only if original image is bigger

Default value is false

  • access: public
bool $image_ratio_no_zoom_out

Set this variable to keep the original size ratio to fit within image_x x image_y, but only if original image is smaller

Default value is false

  • access: public
mixed $image_ratio_pixels

Set this variable to a number of pixels so that image_x and image_y are the best match possible

The image will be resized to have approximatively the number of pixels The aspect ratio wil be conserved

Default value is false

  • access: public
bool $image_ratio_x

Set this variable to calculate image_x automatically , using image_y and conserving ratio

Default value is false

  • access: public
bool $image_ratio_y

Set this variable to calculate image_y automatically , using image_x and conserving ratio

Default value is false

  • access: public
string; $image_reflection_color

Sets the color of the reflection background (deprecated)

Value is an hexadecimal color, such as #FFFFFF

Default value is #FFFFFF

This setting is relevant only if image_reflection_height is set

This setting is now deprecated in favor of image_default_color

  • access: public
mixed; $image_reflection_height

Sets the height of the reflection

Value is an integer in pixels, or a string which format can be in pixels or percentage. For instance, values can be : 40, '40', '40px' or '40%'

Default value is null, no reflection

  • access: public
integer $image_reflection_opacity

Sets the initial opacity of the reflection

Value is an integer between 0 (no opacity) and 100 (full opacity). The reflection will start from image_reflection_opacity and end up at 0

Default value is 60

This setting is relevant only if image_reflection_height is set

  • access: public
integer $image_reflection_space

Sets the space between the source image and its relection

Value is an integer in pixels, which can be negative

Default value is 2

This setting is relevant only if image_reflection_height is set

  • access: public
bool $image_resize

Set this variable to true to resize the file if it is an image

You will probably want to set image_x and image_y, and maybe one of the ratio variables

Default value is false (no resizing)

  • access: public
string; $image_rotate

Rotates the image by increments of 45 degrees

Value is either 90, 180 or 270

Default value is null (no rotation)

  • access: public
integer $image_src_bits

Source image color depth

  • access: public
long $image_src_pixels

Number of pixels

  • access: public
string $image_src_type

Type of image (png, gif, jpg or bmp)

  • access: public
integer $image_src_x

Source image width

  • access: public
integer $image_src_y

Source image height

  • access: public
string; $image_text

Adds a text label on the image

Value is a string, any text. Text will not word-wrap, although you can use breaklines in your text "\n"

If set, this setting allow the use of all other settings starting with image_text_

Replacement tokens can be used in the string:

 gd_version    src_name       src_name_body src_name_ext
 src_pathname  src_mime       src_x         src_y
 src_type      src_bits       src_pixels
 src_size      src_size_kb    src_size_mb   src_size_human
 dst_path      dst_name_body  dst_pathname
 dst_name      dst_name_ext   dst_x         dst_y
 date          time           host          server        ip
The tokens must be enclosed in square brackets: [dst_x] will be replaced by the width of the picture

Default value is null

  • access: public
string; $image_text_alignment

Sets the text alignment

Value is a string, which can be either 'L', 'C' or 'R'

Default value is 'C'

This setting is relevant only if the text has several lines.

  • access: public
string; $image_text_background

Sets the text background color for the text label

Value is an hexadecimal color, such as #FFFFFF

Default value is null (no background)

  • access: public
integer $image_text_background_opacity

Sets the text background opacity in the text label

Value is a percentage, as an integer between 0 (transparent) and 100 (opaque)

Default value is 100

  • access: public
integer $image_text_background_percent

Soon to be deprecated old form of image_text_background_opacity

  • access: public
string; $image_text_color

Sets the text color for the text label

Value is an hexadecimal color, such as #FFFFFF

Default value is #FFFFFF (white)

  • access: public
string; $image_text_direction

Sets the text direction for the text label

Value is either 'h' or 'v', as in horizontal and vertical

Default value is h (horizontal)

  • access: public
mixed; $image_text_font

Sets the text font in the text label

Value is a an integer between 1 and 5 for GD built-in fonts. 1 is the smallest font, 5 the biggest Value can also be a string, which represents the path to a GDF font. The font will be loaded into GD, and used as a built-in font.

Default value is 5

  • access: public
integer $image_text_line_spacing

Sets the text line spacing

Value is an integer, in pixels

Default value is 0

This setting is relevant only if the text has several lines.

  • access: public
integer $image_text_opacity

Sets the text opacity in the text label

Value is a percentage, as an integer between 0 (transparent) and 100 (opaque)

Default value is 100

  • access: public
integer $image_text_padding

Sets the text label padding

Value is in pixels, representing the distance between the text and the label background border

Default value is 0

This setting can be overriden by image_text_padding_x and image_text_padding_y

  • access: public
integer $image_text_padding_x

Sets the text label horizontal padding

Value is in pixels, representing the distance between the text and the left and right label background borders

Default value is null

If set, this setting overrides the horizontal part of image_text_padding

  • access: public
integer $image_text_padding_y

Sets the text label vertical padding

Value is in pixels, representing the distance between the text and the top and bottom label background borders

Default value is null

If set, his setting overrides the vertical part of image_text_padding

  • access: public
integer $image_text_percent

Soon to be deprecated old form of image_text_opacity

  • access: public
string; $image_text_position

Sets the text label position within the image

Value is one or two out of 'TBLR' (top, bottom, left, right)

The positions are as following:

                        TL  T  TR
                        L       R
                        BL  B  BR

Default value is null (centered, horizontal and vertical)

Note that is image_text_x and image_text_y are used, this setting has no effect

  • access: public
integer $image_text_x

Sets the text label absolute X position within the image

Value is in pixels, representing the distance between the left of the image and the label If a negative value is used, it will represent the distance between the right of the image and the label

Default value is null (so image_text_position is used)

  • access: public
integer $image_text_y

Sets the text label absolute Y position within the image

Value is in pixels, representing the distance between the top of the image and the label If a negative value is used, it will represent the distance between the bottom of the image and the label

Default value is null (so image_text_position is used)

  • access: public
integer $image_threshold

Applies threshold filter

Value can range between -127 and 127

Default value is null

  • access: public
string; $image_tint_color

Applies a tint on the image

Value is an hexadecimal color, such as #FFFFFF

Default value is null

  • access: public
boolean $image_transparent_color

Transparent color in a palette

This is actually used only for transparent GIFs

  • access: public
boolean; $image_unsharp

Applies an unsharp mask, with alpha transparency support

Beware that this unsharp mask is quite resource-intensive

Default value is FALSE

  • access: public
integer $image_unsharp_amount

Sets the unsharp mask amount

Value is an integer between 0 and 500, typically between 50 and 200

Unless used with image_unsharp, this setting has no effect

Default value is 80

  • access: public
integer $image_unsharp_radius

Sets the unsharp mask radius

Value is an integer between 0 and 50, typically between 0.5 and 1 It is not recommended to change it, the default works best

Unless used with image_unsharp, this setting has no effect

From PHP 5.1, imageconvolution is used, and this setting has no effect

Default value is 0.5

  • access: public
integer $image_unsharp_threshold

Sets the unsharp mask threshold

Value is an integer between 0 and 255, typically between 0 and 5

Unless used with image_unsharp, this setting has no effect

Default value is 1

  • access: public
string; $image_watermark

Adds a watermark on the image

Value is a local image filename, relative or absolute. GIF, JPG, BMP and PNG are supported, as well as PNG alpha.

If set, this setting allow the use of all other settings starting with image_watermark_

Default value is null

  • access: public
integer $image_watermark_no_zoom_in

Prevents the watermark to be resized up if it is smaller than the image

If the watermark if smaller than the destination image, taking in account the desired watermark position then it will be resized up to fill in the image (minus the image_watermark_x or image_watermark_y values)

If you don't want your watermark to be resized in any way, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to true If you want your watermark to be resized up or doan to fill in the image better, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to false

Default value is true (so the watermark will not be resized up, which is the behaviour most people expect)

  • access: public
integer $image_watermark_no_zoom_out

Prevents the watermark to be resized down if it is bigger than the image

If the watermark if bigger than the destination image, taking in account the desired watermark position then it will be resized down to fit in the image (minus the image_watermark_x or image_watermark_y values)

If you don't want your watermark to be resized in any way, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to true If you want your watermark to be resized up or doan to fill in the image better, then set image_watermark_no_zoom_in and image_watermark_no_zoom_out to false

Default value is false (so the watermark may be shrinked to fit in the image)

  • access: public
string; $image_watermark_position

Sets the watermarkposition within the image

Value is one or two out of 'TBLR' (top, bottom, left, right)

The positions are as following: TL T TR L R BL B BR

Default value is null (centered, horizontal and vertical)

Note that is image_watermark_x and image_watermark_y are used, this setting has no effect

  • access: public
integer $image_watermark_x

Sets the watermark absolute X position within the image

Value is in pixels, representing the distance between the top of the image and the watermark If a negative value is used, it will represent the distance between the bottom of the image and the watermark

Default value is null (so image_watermark_position is used)

  • access: public
integer $image_watermark_y

Sets the twatermark absolute Y position within the image

Value is in pixels, representing the distance between the left of the image and the watermark If a negative value is used, it will represent the distance between the right of the image and the watermark

Default value is null (so image_watermark_position is used)

  • access: public
integer $image_x

Set this variable to the wanted (or maximum/minimum) width for the processed image, in pixels

Default value is 150

  • access: public
integer $image_y

Set this variable to the wanted (or maximum/minimum) height for the processed image, in pixels

Default value is 150

  • access: public
integer $jpeg_quality

Quality of JPEG created/converted destination image

Default value is 85

  • access: public
integer $jpeg_size

Determines the quality of the JPG image to fit a desired file size

The JPG quality will be set between 1 and 100% The calculations are approximations.

Value in bytes (integer) or shorthand byte values (string) is allowed. The available options are K (for Kilobytes), M (for Megabytes) and G (for Gigabytes)

Default value is null (no calculations)

  • access: public
array $language

Language selected for the translations

By default, the language is english ("en_GB")

  • access: public
string $log

Holds an HTML formatted log

  • access: public
boolean $mime_check

Set this variable to false if you don't want to check the MIME against the allowed list

This variable is set to true by default for security reason

  • access: public
boolean $mime_file

Set this variable to false in the init() function if you don't want to check the MIME with UNIX file() command

This variable is set to true by default for security reason

  • access: public
boolean $mime_fileinfo

Set this variable to false in the init() function if you don't want to check the MIME with Fileinfo PECL extension. On some systems, Fileinfo is known to be buggy, and you may want to deactivate it in the class code directly.

You can also set it with the path of the magic database file. If set to true, the class will try to read the MAGIC environment variable and if it is empty, will default to the system's default If set to an empty string, it will call finfo_open without the path argument

This variable is set to true by default for security reason

  • access: public
boolean $mime_getimagesize

Set this variable to false in the init() function if you don't want to check the MIME with getimagesize()

The class tries to get a MIME type from getimagesize() If no MIME is returned, it tries to guess the MIME type from the file type

This variable is set to true by default for security reason

  • access: public
boolean $mime_magic

Set this variable to false in the init() function if you don't want to check the MIME with the magic.mime file

The function mime_content_type() will be deprecated, and this variable will be set to false in a future release

This variable is set to true by default for security reason

  • access: public
boolean $no_script

Set this variable to false if you don't want to turn dangerous scripts into simple text files

  • access: public
bool $no_upload_check

Flag stopping PHP upload checks

Indicates whether we instanciated the class with a filename, in which case we will not check on the validity of the PHP *upload*

This flag is automatically set to true when working on a local file

Warning: for uploads, this flag MUST be set to false for security reason

  • access: public
integer $png_compression

Compression level for PNG images

Between 1 (fast but large files) and 9 (slow but smaller files)

Default value is null (Zlib default)

  • access: public
integer $preserve_transparency

Preserve transparency when resizing or converting an image (deprecated)

Default value is automatically set to true for transparent GIFs This setting is now deprecated

  • access: public
bool $processed

Flag set after calling a process

Indicates if the processing, and copy of the resulting file went OK

  • access: public
array $translation

Array of translated error messages

By default, the language is english (en_GB) Translations can be in separate files, in a lang/ subdirectory

  • access: public
bool $uploaded

Flag set after instanciating the class

Indicates if the file has been uploaded properly

  • access: public
string $version

Class version

  • access: public
Methods
clean

Deletes the uploaded file from its temporary location

When PHP uploads a file, it stores it in a temporary location. When you process the file, you actually copy the resulting file to the given location, it doesn't alter the original file. Once you have processed the file as many times as you wanted, you can delete the uploaded file. If there is open_basedir restrictions, the uploaded file is in fact a temporary file

You might want not to use this function if you work on local files, as it will delete the source file

  • access: public
void clean ()
gdversion

Returns the version of GD

  • return: GD version
  • access: public
float gdversion ([boolean $full = false])
  • boolean $full: Optional flag to get precise version
imagebmp

Saves a BMP image

This function has been published on the PHP website, and can be used freely

  • access: public
void imagebmp ( &$im, [ $filename = ""])
  • &$im
  • $filename
imagecreatefrombmp

Opens a BMP image

This function has been written by DHKold, and is used with permission of the author

  • access: public
void imagecreatefrombmp ( $filename)
  • $filename
process

Actually uploads the file, and act on it according to the set processing class variables

This function copies the uploaded file to the given location, eventually performing actions on it. Typically, you can call process several times for the same file, for instance to create a resized image and a thumbnail of the same file. The original uploaded file remains intact in its temporary location, so you can use process several times. You will be able to delete the uploaded file with clean when you have finished all your process calls.

According to the processing class variables set in the calling file, the file can be renamed, and if it is an image, can be resized or converted.

When the processing is completed, and the file copied to its new location, the processing class variables will be reset to their default value. This allows you to set new properties, and perform another process on the same uploaded file

If the function is called with a null or empty argument, then it will return the content of the picture

It will set processed (and error is an error occurred)

  • return: Optional content of the image
  • access: public
string process ([string $server_path = null])
  • string $server_path: Optional path location of the uploaded file, with an ending slash