Source for file class.upload.php 0.24

Documentation is available at class.upload.php

Webpage is available at http://www.verot.net/php_class_upload.htm

  1. <?php
  2. // +------------------------------------------------------------------------+
  3. // | class.upload.php                                                       |
  4. // +------------------------------------------------------------------------+
  5. // | Copyright (c) Colin Verot 2003-2008. All rights reserved.              |
  6. // | Version       0.26                                                     |
  7. // | Last modified 13/11/2008                                               |
  8. // | Email         colin@verot.net                                          |
  9. // | Web           http://www.verot.net                                     |
  10. // +------------------------------------------------------------------------+
  11. // | This program is free software; you can redistribute it and/or modify   |
  12. // | it under the terms of the GNU General Public License version 2 as      |
  13. // | published by the Free Software Foundation.                             |
  14. // |                                                                        |
  15. // | This program is distributed in the hope that it will be useful,        |
  16. // | but WITHOUT ANY WARRANTY; without even the implied warranty of         |
  17. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          |
  18. // | GNU General Public License for more details.                           |
  19. // |                                                                        |
  20. // | You should have received a copy of the GNU General Public License      |
  21. // | along with this program; if not, write to the                          |
  22. // |   Free Software Foundation, Inc., 59 Temple Place, Suite 330,          |
  23. // |   Boston, MA 02111-1307 USA                                            |
  24. // |                                                                        |
  25. // | Please give credit on sites that use class.upload and submit changes   |
  26. // | of the script so other people can use them as well.                    |
  27. // | This script is free to use, don't abuse.                               |
  28. // +------------------------------------------------------------------------+
  29. //
  30.  
  31. /**
  32.  * Class upload
  33.  *
  34.  * @version   0.26
  35.  * @author    Colin Verot <colin@verot.net>
  36.  * @license   http://opensource.org/licenses/gpl-license.php GNU Public License
  37.  * @copyright Colin Verot
  38.  * @package   cmf
  39.  * @subpackage external
  40.  */
  41.  
  42. /**
  43.  * Class upload
  44.  *
  45.  * <b>What does it do?</b>
  46.  *
  47.  * It manages file uploads for you. In short, it manages the uploaded file,
  48.  * and allows you to do whatever you want with the file, especially if it
  49.  * is an image, and as many times as you want.
  50.  *
  51.  * It is the ideal class to quickly integrate file upload in your site.
  52.  * If the file is an image, you can convert, resize, crop it in many ways.
  53.  * You can also apply filters, add borders, text, watermarks, etc...
  54.  * That's all you need for a gallery script for instance. Supported formats
  55.  * are PNG, JPG, GIF and BMP.
  56.  *
  57.  * You can also use the class to work on local files, which is especially
  58.  * useful to use the image manipulation features. The class also supports
  59.  * Flash uploaders.
  60.  *
  61.  * The class works with PHP 4 and 5, and its error messages can
  62.  * be localized at will.
  63.  *
  64.  * <b>How does it work?</b>
  65.  *
  66.  * You instanciate the class with the $_FILES['my_field'] array
  67.  * where my_field is the field name from your upload form.
  68.  * The class will check if the original file has been uploaded
  69.  * to its temporary location (alternatively, you can instanciate
  70.  * the class with a local filename).
  71.  *
  72.  * You can then set a number of processing variables to act on the file.
  73.  * For instance, you can rename the file, and if it is an image,
  74.  * convert and resize it in many ways.
  75.  * You can also set what will the class do if the file already exists.
  76.  *
  77.  * Then you call the function {@link process} to actually perform the actions
  78.  * according to the processing parameters you set above.
  79.  * It will create new instances of the original file,
  80.  * so the original file remains the same between each process.
  81.  * The file will be manipulated, and copied to the given location.
  82.  * The processing variables will be reset once it is done.
  83.  *
  84.  * You can repeat setting up a new set of processing variables,
  85.  * and calling {@link process} again as many times as you want.
  86.  * When you have finished, you can call {@link clean} to delete
  87.  * the original uploaded file.
  88.  *
  89.  * If you don't set any processing parameters and call {@link process}
  90.  * just after instanciating the class. The uploaded file will be simply
  91.  * copied to the given location without any alteration or checks.
  92.  *
  93.  * Don't forget to add <i>enctype="multipart/form-data"</i> in your form
  94.  * tag <form> if you want your form to upload the file.
  95.  *
  96.  * <b>How to use it?</b><br>
  97.  * Create a simple HTML file, with a form such as:
  98.  * <pre>
  99.  * <form enctype="multipart/form-data" method="post" action="upload.php">
  100.  *   <input type="file" size="32" name="image_field" value="">
  101.  *   <input type="submit" name="Submit" value="upload">
  102.  * </form>
  103.  * </pre>
  104.  * Create a file called upload.php:
  105.  * <pre>
  106.  *  $handle = new upload($_FILES['image_field']);
  107.  *  if ($handle->uploaded) {
  108.  *      $handle->file_new_name_body   = 'image_resized';
  109.  *      $handle->image_resize         = true;
  110.  *      $handle->image_x              = 100;
  111.  *      $handle->image_ratio_y        = true;
  112.  *      $handle->process('/home/user/files/');
  113.  *      if ($handle->processed) {
  114.  *          echo 'image resized';
  115.  *          $handle->clean();
  116.  *      } else {
  117.  *          echo 'error : ' . $handle->error;
  118.  *      }
  119.  *  }
  120.  * </pre>
  121.  *
  122.  * <b>How to process local files?</b><br>
  123.  * Use the class as following, the rest being the same as above:
  124.  * <pre>
  125.  *  $handle = new upload('/home/user/myfile.jpg');
  126.  * </pre>
  127.  *
  128.  * <b>How to set the language?</b><br>
  129.  * Instantiate the class with a second argument being the language code:
  130.  * <pre>
  131.  *  $handle = new upload($_FILES['image_field'], 'fr_FR');
  132.  *  $handle = new upload('/home/user/myfile.jpg', 'fr_FR');
  133.  * </pre>
  134.  *
  135.  * <b>How to output the resulting file or picture directly to the browser?</b><br>
  136.  * Simply call {@link process}() without an argument (or with null as first argument):
  137.  * <pre>
  138.  *  $handle = new upload($_FILES['image_field']);
  139.  *  header('Content-type: ' . $handle->file_src_mime);
  140.  *  echo $handle->Process();
  141.  *  die();
  142.  * </pre>
  143.  * Or if you want to force the download of the file:
  144.  * <pre>
  145.  *  $handle = new upload($_FILES['image_field']);
  146.  *  header('Content-type: ' . $handle->file_src_mime);
  147.  *  header("Content-Disposition: attachment; filename=".rawurlencode($handle->file_src_name).";");
  148.  *  echo $handle->Process();
  149.  *  die();
  150.  * </pre>
  151.  *
  152.  * <b>Processing parameters</b> (reset after each process)
  153.  * <ul>
  154.  *  <li><b>file_new_name_body</b> replaces the name body (default: '')<br>
  155.  *  <pre>$handle->file_new_name_body = 'new name';</pre></li>
  156.  *  <li><b>file_name_body_add</b> appends to the name body (default: '')<br>
  157.  *  <pre>$handle->file_name_body_add = '_uploaded';</pre></li>
  158.  *  <li><b>file_new_name_ext</b> replaces the file extension (default: '')<br>
  159.  *  <pre>$handle->file_new_name_ext = 'txt';</pre></li>
  160.  *  <li><b>file_safe_name</b> formats the filename (spaces changed to _) (default: true)<br>
  161.  *  <pre>$handle->file_safe_name = true;</pre></li>
  162.  *  <li><b>file_overwrite</b> sets behaviour if file already exists (default: false)<br>
  163.  *  <pre>$handle->file_overwrite = true;</pre></li>
  164.  *  <li><b>file_auto_rename</b> automatically renames file if it already exists (default: true)<br>
  165.  *  <pre>$handle->file_auto_rename = true;</pre></li>
  166.  *  <li><b>auto_create_dir</b> automatically creates destination directory if missing (default: true)<br>
  167.  *  <pre>$handle->auto_create_dir = true;</pre></li>
  168.  *  <li><b>dir_auto_chmod</b> automatically attempts to chmod the destination directory if not writeable (default: true)<br>
  169.  *  <pre>$handle->dir_auto_chmod = true;</pre></li>
  170.  *  <li><b>dir_chmod</b> chmod used when creating directory or if directory not writeable (default: 0777)<br>
  171.  *  <pre>$handle->dir_chmod = 0777;</pre></li>
  172.  *  <li><b>file_max_size</b> sets maximum upload size (default: upload_max_filesize from php.ini)<br>
  173.  *  <pre>$handle->file_max_size = '1024'; // 1KB</pre></li>
  174.  *  <li><b>mime_check</b> sets if the class check the MIME against the {@link allowed} list (default: true)<br>
  175.  *  <pre>$handle->mime_magic_check = true;</pre></li>
  176.  *  <li><b>no_script</b> sets if the class turns scripts into text files (default: true)<br>
  177.  *  <pre>$handle->no_script = false;</pre></li>
  178.  *  <li><b>allowed</b> array of allowed mime-types. wildcard accepted, as in image/* (default: check {@link Init})<br>
  179.  *  <pre>$handle->allowed = array('application/pdf','application/msword', 'image/*');</pre></li>
  180.  *  <li><b>forbidden</b> array of forbidden mime-types. wildcard accepted, as in image/*  (default: check {@link Init})<br>
  181.  *  <pre>$handle->forbidden = array('application/*');</pre></li>
  182.  * </ul>
  183.  * <ul>
  184.  *  <li><b>image_convert</b> if set, image will be converted (possible values : ''|'png'|'jpeg'|'gif'|'bmp'; default: '')<br>
  185.  *  <pre>$handle->image_convert = 'jpg';</pre></li>
  186.  *  <li><b>image_background_color</b> if set, will forcibly fill transparent areas with the color, in hexadecimal (default: null)<br>
  187.  *  <pre>$handle->image_background_color = '#FF00FF';</pre></li>
  188.  *  <li><b>image_default_color</b> fallback color background color for non alpha-transparent output formats, such as JPEG or BMP, in hexadecimal (default: #FFFFFF)<br>
  189.  *  <pre>$handle->image_default_color = '#FF00FF';</pre></li>
  190.  *  <li><b>jpeg_quality</b> sets the compression quality for JPEG images (default: 85)<br>
  191.  *  <pre>$handle->jpeg_quality = 50;</pre></li>
  192.  *  <li><b>jpeg_size</b> if set to a size in bytes, will approximate {@link jpeg_quality} so the output image fits within the size (default: null)<br>
  193.  *  <pre>$handle->jpeg_size = 3072;</pre></li>
  194.  * </ul>
  195.  * The following eight settings can be used to invalidate an upload if the file is an image (note that <i>open_basedir</i> restrictions prevent the use of these settings)
  196.  * <ul>
  197.  *  <li><b>image_max_width</b> if set to a dimension in pixels, the upload will be invalid if the image width is greater (default: null)<br>
  198.  *  <pre>$handle->image_max_width = 200;</pre></li>
  199.  *  <li><b>image_max_height</b> if set to a dimension in pixels, the upload will be invalid if the image height is greater (default: null)<br>
  200.  *  <pre>$handle->image_max_height = 100;</pre></li>
  201.  *  <li><b>image_max_pixels</b> if set to a number of pixels, the upload will be invalid if the image number of pixels is greater (default: null)<br>
  202.  *  <pre>$handle->image_max_pixels = 50000;</pre></li>
  203.  *  <li><b>image_max_ratio</b> if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is greater (default: null)<br>
  204.  *  <pre>$handle->image_max_ratio = 1.5;</pre></li>
  205.  *  <li><b>image_min_width</b> if set to a dimension in pixels, the upload will be invalid if the image width is lower (default: null)<br>
  206.  *  <pre>$handle->image_min_width = 100;</pre></li>
  207.  *  <li><b>image_min_height</b> if set to a dimension in pixels, the upload will be invalid if the image height is lower (default: null)<br>
  208.  *  <pre>$handle->image_min_height = 500;</pre></li>
  209.  *  <li><b>image_min_pixels</b> if set to a number of pixels, the upload will be invalid if the image number of pixels is lower (default: null)<br>
  210.  *  <pre>$handle->image_min_pixels = 20000;</pre></li>
  211.  *  <li><b>image_min_ratio</b> if set to a aspect ratio (width/height), the upload will be invalid if the image apect ratio is lower (default: null)<br>
  212.  *  <pre>$handle->image_min_ratio = 0.5;</pre></li>
  213.  * </ul>
  214.  * <ul>
  215.  *  <li><b>image_resize</b> determines is an image will be resized (default: false)<br>
  216.  *  <pre>$handle->image_resize = true;</pre></li>
  217.  * </ul>
  218.  *  The following variables are used only if {@link image_resize} == true
  219.  * <ul>
  220.  *  <li><b>image_x</b> destination image width (default: 150)<br>
  221.  *  <pre>$handle->image_x = 100;</pre></li>
  222.  *  <li><b>image_y</b> destination image height (default: 150)<br>
  223.  *  <pre>$handle->image_y = 200;</pre></li>
  224.  * </ul>
  225.  *  Use either one of the following
  226.  * <ul>
  227.  *  <li><b>image_ratio</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link image_y} as max sizes if true (default: false)<br>
  228.  *  <pre>$handle->image_ratio = true;</pre></li>
  229.  *  <li><b>image_ratio_crop</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link 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)<br>
  230.  *  <pre>$handle->image_ratio_crop = true;</pre></li>
  231.  *  <li><b>image_ratio_fill</b> if true, resize image conserving the original sizes ratio, using {@link image_x} AND {@link 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)<br>
  232.  *  <pre>$handle->image_ratio_fill = true;</pre></li>
  233.  *  <li><b>image_ratio_no_zoom_in</b> same as {@link image_ratio}, but won't resize if the source image is smaller than {@link image_x} x {@link image_y} (default: false)<br>
  234.  *  <pre>$handle->image_ratio_no_zoom_in = true;</pre></li>
  235.  *  <li><b>image_ratio_no_zoom_out</b> same as {@link image_ratio}, but won't resize if the source image is bigger than {@link image_x} x {@link image_y} (default: false)<br>
  236.  *  <pre>$handle->image_ratio_no_zoom_out = true;</pre></li>
  237.  *  <li><b>image_ratio_x</b> if true, resize image, calculating {@link image_x} from {@link image_y} and conserving the original sizes ratio (default: false)<br>
  238.  *  <pre>$handle->image_ratio_x = true;</pre></li>
  239.  *  <li><b>image_ratio_y</b> if true, resize image, calculating {@link image_y} from {@link image_x} and conserving the original sizes ratio (default: false)<br>
  240.  *  <pre>$handle->image_ratio_y = true;</pre></li>
  241.  *  <li><b>image_ratio_pixels</b> if set to a long integer, resize image, calculating {@link image_y} and {@link image_x} to match a the number of pixels (default: false)<br>
  242.  *  <pre>$handle->image_ratio_pixels = 25000;</pre></li>
  243.  * </ul>
  244.  *  The following image manipulations require GD2+
  245.  * <ul>
  246.  *  <li><b>image_brightness</b> if set, corrects the brightness. value between -127 and 127 (default: null)<br>
  247.  *  <pre>$handle->image_brightness = 40;</pre></li>
  248.  *  <li><b>image_contrast</b> if set, corrects the contrast. value between -127 and 127 (default: null)<br>
  249.  *  <pre>$handle->image_contrast = 50;</pre></li>
  250.  *  <li><b>image_tint_color</b> if set, will tint the image with a color, value as hexadecimal #FFFFFF (default: null)<br>
  251.  *  <pre>$handle->image_tint_color = '#FF0000';</pre></li>
  252.  *  <li><b>image_overlay_color</b> if set, will add a colored overlay, value as hexadecimal #FFFFFF (default: null)<br>
  253.  *  <pre>$handle->image_overlay_color = '#FF0000';</pre></li>
  254.  *  <li><b>image_overlay_percent</b> used when {@link image_overlay_color} is set, determines the opacity (default: 50)<br>
  255.  *  <pre>$handle->image_overlay_percent = 20;</pre></li>
  256.  *  <li><b>image_negative</b> inverts the colors in the image (default: false)<br>
  257.  *  <pre>$handle->image_negative = true;</pre></li>
  258.  *  <li><b>image_greyscale</b> transforms an image into greyscale (default: false)<br>
  259.  *  <pre>$handle->image_greyscale = true;</pre></li>
  260.  *  <li><b>image_threshold</b> applies a threshold filter. value between -127 and 127 (default: null)<br>
  261.  *  <pre>$handle->image_threshold = 20;</pre></li>
  262.  * </ul>
  263.  * <ul>
  264.  *  <li><b>image_text</b> creates a text label on the image, value is a string, with eventual replacement tokens (default: null)<br>
  265.  *  <pre>$handle->image_text = 'test';</pre></li>
  266.  *  <li><b>image_text_direction</b> text label direction, either 'h' horizontal or 'v' vertical (default: 'h')<br>
  267.  *  <pre>$handle->image_text_direction = 'v';</pre></li>
  268.  *  <li><b>image_text_color</b> text color for the text label, in hexadecimal (default: #FFFFFF)<br>
  269.  *  <pre>$handle->image_text_color = '#FF0000';</pre></li>
  270.  *  <li><b>image_text_percent</b> text opacity on the text label, integer between 0 and 100 (default: 100)<br>
  271.  *  <pre>$handle->image_text_percent = 50;</pre></li>
  272.  *  <li><b>image_text_background</b> text label background color, in hexadecimal (default: null)<br>
  273.  *  <pre>$handle->image_text_background = '#FFFFFF';</pre></li>
  274.  *  <li><b>image_text_background_percent</b> text label background opacity, integer between 0 and 100 (default: 100)<br>
  275.  *  <pre>$handle->image_text_background_percent = 50;</pre></li>
  276.  *  <li><b>image_text_font</b> built-in font for the text label, from 1 to 5. 1 is the smallest (default: 5)<br>
  277.  *  <pre>$handle->image_text_font = 4;</pre></li>
  278.  *  <li><b>image_text_x</b> absolute text label position, in pixels from the left border. can be negative (default: null)<br>
  279.  *  <pre>$handle->image_text_x = 5;</pre></li>
  280.  *  <li><b>image_text_y</b> absolute text label position, in pixels from the top border. can be negative (default: null)<br>
  281.  *  <pre>$handle->image_text_y = 5;</pre></li>
  282.  *  <li><b>image_text_position</b> text label position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)<br>
  283.  *  <pre>$handle->image_text_position = 'LR';</pre></li>
  284.  *  <li><b>image_text_padding</b> text label padding, in pixels. can be overridden by {@link image_text_padding_x} and {@link image_text_padding_y} (default: 0)<br>
  285.  *  <pre>$handle->image_text_padding = 5;</pre></li>
  286.  *  <li><b>image_text_padding_x</b> text label horizontal padding (default: null)<br>
  287.  *  <pre>$handle->image_text_padding_x = 2;</pre></li>
  288.  *  <li><b>image_text_padding_y</b> text label vertical padding (default: null)<br>
  289.  *  <pre>$handle->image_text_padding_y = 10;</pre></li>
  290.  *  <li><b>image_text_alignment</b> text alignment when text has multiple lines, either 'L', 'C' or 'R' (default: 'C')<br>
  291.  *  <pre>$handle->image_text_alignment = 'R';</pre></li>
  292.  *  <li><b>image_text_line_spacing</b> space between lines in pixels, when text has multiple lines (default: 0)<br>
  293.  *  <pre>$handle->image_text_line_spacing = 3;</pre></li>
  294.  * </ul>
  295.  * <ul>
  296.  *  <li><b>image_flip</b> flips image, wither 'h' horizontal or 'v' vertical (default: null)<br>
  297.  *  <pre>$handle->image_flip = 'h';</pre></li>
  298.  *  <li><b>image_rotate</b> rotates image. possible values are 90, 180 and 270 (default: null)<br>
  299.  *  <pre>$handle->image_rotate = 90;</pre></li>
  300.  *  <li><b>image_crop</b> 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)<br>
  301.  *  <pre>$handle->image_crop = array(50,40,30,20); OR '-20 20%'...</pre></li>
  302.  * </ul>
  303.  * <ul>
  304.  *  <li><b>image_bevel</b> adds a bevel border to the image. value is thickness in pixels (default: null)<br>
  305.  *  <pre>$handle->image_bevel = 20;</pre></li>
  306.  *  <li><b>image_bevel_color1</b> top and left bevel color, in hexadecimal (default: #FFFFFF)<br>
  307.  *  <pre>$handle->image_bevel_color1 = '#FFFFFF';</pre></li>
  308.  *  <li><b>image_bevel_color2</b> bottom and right bevel color, in hexadecimal (default: #000000)<br>
  309.  *  <pre>$handle->image_bevel_color2 = '#000000';</pre></li>
  310.  *  <li><b>image_border</b> 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)<br>
  311.  *  <pre>$handle->image_border = '3px'; OR '-20 20%' OR array(3,2)...</pre></li>
  312.  *  <li><b>image_border_color</b> border color, in hexadecimal (default: #FFFFFF)<br>
  313.  *  <pre>$handle->image_border_color = '#FFFFFF';</pre></li>
  314.  *  <li><b>image_frame</b> type of frame: 1=flat 2=crossed (default: null)<br>
  315.  *  <pre>$handle->image_frame = 2;</pre></li>
  316.  *  <li><b>image_frame_colors</b> list of hex colors, in an array or a space separated string (default: '#FFFFFF #999999 #666666 #000000')<br>
  317.  *  <pre>$handle->image_frame_colors = array('#999999',  '#FF0000', '#666666', '#333333', '#000000');</pre></li>
  318.  * </ul>
  319.  * <ul>
  320.  *  <li><b>image_watermark</b> adds a watermark on the image, value is a local filename. accepted files are GIF, JPG, BMP, PNG and PNG alpha (default: null)<br>
  321.  *  <pre>$handle->image_watermark = 'watermark.png';</pre></li>
  322.  *  <li><b>image_watermark_x</b> absolute watermark position, in pixels from the left border. can be negative (default: null)<br>
  323.  *  <pre>$handle->image_watermark_x = 5;</pre></li>
  324.  *  <li><b>image_watermark_y</b> absolute watermark position, in pixels from the top border. can be negative (default: null)<br>
  325.  *  <pre>$handle->image_watermark_y = 5;</pre></li>
  326.  *  <li><b>image_watermark_position</b> watermark position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)<br>
  327.  *  <pre>$handle->image_watermark_position = 'LR';</pre></li>
  328.  * </ul>
  329.  * <ul>
  330.  *  <li><b>image_reflection_height</b> if set, a reflection will be added. Format is either in pixels or percentage, such as 40, '40', '40px' or '40%' (default: null)<br>
  331.  *  <pre>$handle->image_reflection_height = '25%';</pre></li>
  332.  *  <li><b>image_reflection_space</b> space in pixels between the source image and the reflection, can be negative (default: null)<br>
  333.  *  <pre>$handle->image_reflection_space = 3;</pre></li>
  334.  *  <li><b>image_reflection_color</b> reflection background color, in hexadecimal. Now deprecated in favor of {@link image_default_color} (default: #FFFFFF)<br>
  335.  *  <pre>$handle->image_default_color = '#000000';</pre></li>
  336.  *  <li><b>image_reflection_opacity</b> opacity level at which the reflection starts, integer between 0 and 100 (default: 60)<br>
  337.  *  <pre>$handle->image_reflection_opacity = 60;</pre></li>
  338.  * </ul>
  339.  *
  340.  * <b>Values that can be read before calling {@link process}()</b>
  341.  * <ul>
  342.  *  <li><b>file_src_name</b> Source file name</li>
  343.  *  <li><b>file_src_name_body</b> Source file name body</li>
  344.  *  <li><b>file_src_name_ext</b> Source file extension</li>
  345.  *  <li><b>file_src_pathname</b> Source file complete path and name</li>
  346.  *  <li><b>file_src_mime</b> Source file mime type</li>
  347.  *  <li><b>file_src_size</b> Source file size in bytes</li>
  348.  *  <li><b>file_src_error</b> Upload error code</li>
  349.  *  <li><b>file_is_image</b> Boolean flag, true if the file is a supported image type</li>
  350.  * </ul>
  351.  * If the file is a supported image type (and <i>open_basedir</i> restrictions allow it)
  352.  * <ul>
  353.  *  <li><b>image_src_x</b> Source file width in pixels</li>
  354.  *  <li><b>image_src_y</b> Source file height in pixels</li>
  355.  *  <li><b>image_src_pixels</b> Source file number of pixels</li>
  356.  *  <li><b>image_src_type</b> Source file type (png, jpg, gif or bmp)</li>
  357.  *  <li><b>image_src_bits</b> Source file color depth</li>
  358.  * </ul>
  359.  *
  360.  * <b>Values that can be read before after {@link process}()</b>
  361.  * <ul>
  362.  *  <li><b>file_dst_path</b> Destination file path</li>
  363.  *  <li><b>file_dst_name_body</b> Destination file name body</li>
  364.  *  <li><b>file_dst_name_ext</b> Destination file extension</li>
  365.  *  <li><b>file_dst_name</b> Destination file name</li>
  366.  *  <li><b>file_dst_pathname</b> Destination file complete path and name</li>
  367.  * </ul>
  368.  * If the file is a supported image type
  369.  * <ul>
  370.  *  <li><b>image_dst_x</b> Destination file width</li>
  371.  *  <li><b>image_dst_y</b> Destination file height</li>
  372.  *  <li><b>image_convert</b> Destination file format</li>
  373.  * </ul>
  374.  *
  375.  * <b>Requirements</b>
  376.  *
  377.  * Most of the image operations require GD. GD2 is greatly recommended
  378.  *
  379.  * The class is compatible with PHP 4.3+, and compatible with PHP5
  380.  *
  381.  * <b>Changelog</b>
  382.  * <ul>
  383.  *  <li><b>v 0.26</b> 13/11/2008<br>
  384.  *   - rewrote conversion from palette to true color to handle transparency better<br>
  385.  *   - fixed imagecopymergealpha() when the overlayed image is of wrong dimensions<br>
  386.  *   - fixed imagecreatenew() when the image to create have less than 1 pixels width or height<br>
  387.  *   - 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<br>
  388.  *   - added support for Flash uploaders<br>
  389.  *   - some bug fixing and error handling</li>
  390.  *  <li><b>v 0.25</b> 17/11/2007<br>
  391.  *   - added translation files and mechanism to instantiate the class with a language different from English<br>
  392.  *   - added {@link forbidden} to set an array of forbidden MIME types<br>
  393.  *   - implemented support for simple wildcards in {@link allowed} and {@link forbidden}, such as image/*<br>
  394.  *   - preset the file extension to the desired conversion format when converting an image<br>
  395.  *   - added read and write support for BMP images<br>
  396.  *   - added a flag {@link file_is_image} to determine if the file is a supported image type<br>
  397.  *   - the class now provides some information about the image, before calling {@link process}(). Available are {@link image_src_x}{@link image_src_y} and the newly introduced {@link image_src_bits}{@link image_src_pixels} and {@link image_src_type}. Note that this will not work if <i>open_basedir</i> restrictions are in place<br>
  398.  *   - improved logging; now provides useful system information<br>
  399.  *   - added some more pre-processing checks for files that are images: {@link image_max_width}{@link image_max_height}{@link image_max_pixels}{@link image_max_ratio}{@link image_min_width}{@link image_min_height}{@link image_min_pixels} and {@link image_min_ratio}<br>
  400.  *   - added {@link image_ratio_pixels} to resize an image to a number of pixels, keeping aspect ratio<br>
  401.  *   - added {@link image_is_palette} and {@link image_is_transparent} and {@link image_transparent_color} for GIF images<br>
  402.  *   - added {@link image_default_color} to define a fallback color for non alpha-transparent output formats, such as JPEG or BMP<br>
  403.  *   - changed {@link image_background_color}, which now forces transparent areas to be painted<br>
  404.  *   - improved reflections and color overlays so that it works with alpha transparent images<br>
  405.  *   - {@link image_reflection_color} is now deprecated in favour of {@link image_default_color}<br />
  406.  *   - transparent PNGs are now processed in true color, and fully preserving the alpha channel when doing merges<br>
  407.  *   - transparent GIFs are now automatically detected. {@link preserve_transparency} is deprecated<br>
  408.  *   - transparent true color images can be saved as GIF while retaining transparency, semi transparent areas being merged with {@link image_default_color}<br>
  409.  *   - transparent true color images can be saved as JPG/BMP with the semi transparent areas being merged with {@link image_default_color}<br>
  410.  *   - fixed conversion of images to true color<br>
  411.  *   - 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</li>
  412.  *  <li><b>v 0.24</b> 25/05/2007<br>
  413.  *   - added {@link image_background_color}, to set the default background color of an image<br>
  414.  *   - added possibility of using replacement tokens in text labels<br>
  415.  *   - changed default JPEG quality to 85<br>
  416.  *   - fixed a small bug when using greyscale filter and associated filters<br>
  417.  *   - added {@link image_ratio_fill} in order to fit an image within some dimensions and color the remaining space. Very similar to {@link image_ratio_crop}<br>
  418.  *   - improved the recursive creation of directories<br>
  419.  *   - the class now converts palette based images to true colors before doing graphic manipulations</li>
  420.  *  <li><b>v 0.23</b> 23/12/2006<br>
  421.  *   - 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()</li>
  422.  *  <li><b>v 0.22</b> 16/12/2006<br>
  423.  *   - added automatic creation of a temporary file if the upload directory is not within open_basedir<br>
  424.  *   - fixed a bug which was preventing to work on a local file by overwriting it with its processed copy<br>
  425.  *   - added MIME types video/x-ms-wmv and image/x-png and fixed PNG support for IE weird MIME types<br>
  426.  *   - modified {@link image_ratio_crop} so it can accept one or more from string 'TBLR', determining which side of the image is kept while cropping<br>
  427.  *   - added support for multiple lines in the text, using "\n" as a line break<br>
  428.  *   - added {@link image_text_line_spacing} which allow to set the space between several lines of text<br>
  429.  *   - added {@link image_text_alignment} which allow to set the alignment when text has several lines<br>
  430.  *   - {@link image_text_font} can now be set to the path of a GDF font to load external fonts<br>
  431.  *   - added {@link image_reflection_height} to create a reflection of the source image, which height is in pixels or percentage<br>
  432.  *   - added {@link image_reflection_space} to set the space in pixels between the source image and the reflection<br>
  433.  *   - added {@link image_reflection_color} to set the reflection background color<br>
  434.  *   - added {@link image_reflection_opacity} to set the initial level of opacity of the reflection</li>
  435.  *  <li><b>v 0.21</b> 30/09/2006<br>
  436.  *   - added {@link image_ratio_crop} which resizes within {@link image_x} and {@link image_y}, keeping ratio, but filling the space by cropping excedent of image<br>
  437.  *   - added {@link mime_check}, which default is true, to set checks against {@link allowed} MIME list<br>
  438.  *   - if MIME is empty, the class now triggers an error<br>
  439.  *   - color #000000 is OK for {@link image_text_color}, and related text transparency bug fixed<br>
  440.  *   - {@link gd_version}() now uses gd_info(), or else phpinfo()<br>
  441.  *   - fixed path issue when the destination path has no trailing slash on Windows systems <br>
  442.  *   - removed inline functions to be fully PHP5 compatible </li>
  443.  *  <li><b>v 0.20</b> 11/08/2006<br>
  444.  *   - added some more error checking and messages (GD presence, permissions...)<br>
  445.  *   - fix when uploading files without extension<br>
  446.  *   - changed values for {@link image_brightness} and {@link image_contrast} to be between -127 and 127<br>
  447.  *   - added {@link dir_auto_create} to automatically and recursively create destination directory if missing.<br>
  448.  *   - added {@link dir_auto_chmod} to automatically chmod the destination directory if not writeable.<br>
  449.  *   - added {@link dir_chmod} to set the default chmod to use.<br>
  450.  *   - added {@link image_crop} to crop images<br>
  451.  *   - added {@link image_negative} to invert the colors on the image<br>
  452.  *   - added {@link image_greyscale} to turn the image into greyscale<br>
  453.  *   - added {@link image_threshold} to apply a threshold filter on the image<br>
  454.  *   - added {@link image_bevel}{@link image_bevel_color1} and {@link image_bevel_color2} to add a bevel border<br>
  455.  *   - added {@link image_border} and {@link image_border_color} to add a single color border<br>
  456.  *   - added {@link image_frame} and {@link image_frame_colors} to add a multicolored frame</li>
  457.  *  <li><b>v 0.19</b> 29/03/2006<br>
  458.  *   - class is now compatible i18n (thanks Sylwester).<br>
  459.  *   - the class can mow manipulate local files, not only uploaded files (instanciate the class with a local filename).<br>
  460.  *   - {@link file_safe_name} has been improved a bit.<br>
  461.  *   - added {@link image_brightness}{@link image_contrast}{@link image_tint_color}{@link image_overlay_color} and {@link image_overlay_percent} to do color manipulation on the images.<br>
  462.  *   - added {@link image_text} and all derivated settings to add a text label on the image.<br>
  463.  *   - added {@link image_watermark} and all derivated settings to add a watermark image on the image.<br>
  464.  *   - added {@link image_flip} and {@link image_rotate} for more image manipulations<br>
  465.  *   - added {@link jpeg_size} to calculate the JPG compression quality in order to fit within one filesize.</li>
  466.  *  <li><b>v 0.18</b> 02/02/2006<br>
  467.  *   - added {@link no_script} to turn dangerous scripts into text files.<br>
  468.  *   - added {@link mime_magic_check} to set the class to use mime_magic.<br>
  469.  *   - added {@link preserve_transparency} *experimental*. Thanks Gregor.<br>
  470.  *   - fixed size and mime checking, wasn't working :/ Thanks Willem.<br>
  471.  *   - fixed memory leak when resizing images.<br>
  472.  *   - when resizing, it is not necessary anymore to set {@link image_convert}.<br>
  473.  *   - il is now possible to simply convert an image, with no resizing.<br>
  474.  *   - sets the default {@link file_max_size} to upload_max_filesize from php.ini. Thanks Edward</li>
  475.  *  <li><b>v 0.17</b> 28/05/2005<br>
  476.  *   - the class can be used with any version of GD.<br>
  477.  *   - added security check on the file with a list of mime-types.<br>
  478.  *   - changed the license to GPL v2 only</li>
  479.  *  <li><b>v 0.16</b> 19/05/2005<br>
  480.  *   - added {@link file_auto_rename} automatic file renaming if the same filename already exists.<br>
  481.  *   - added {@link file_safe_name} safe formatting of the filename (spaces to _underscores so far).<br>
  482.  *   - added some more error reporting to avoid crash if GD is not present</li>
  483.  *  <li><b>v 0.15</b> 16/04/2005<br>
  484.  *   - added JPEG compression quality setting. Thanks Vad</li>
  485.  *  <li><b>v 0.14</b> 14/03/2005<br>
  486.  *   - reworked the class file to allow parsing with phpDocumentor</li>
  487.  *  <li><b>v 0.13</b> 07/03/2005<br>
  488.  *   - fixed a bug with {@link image_ratio}. Thanks Justin.<br>
  489.  *   - added {@link image_ratio_no_zoom_in} and {@link image_ratio_no_zoom_out}</li>
  490.  *  <li><b>v 0.12</b> 21/01/2005<br>
  491.  *   - added {@link image_ratio} to resize within max values, keeping image ratio</li>
  492.  *  <li><b>v 0.11</b> 22/08/2003<br>
  493.  *   - update for GD2 (changed imageresized() into imagecopyresampled() and imagecreate() into imagecreatetruecolor())</li>
  494.  * </ul>
  495.  *
  496.  * @package   cmf
  497.  * @subpackage external
  498.  */
  499. class upload {
  500.  
  501.  
  502.     /**
  503.      * Class version
  504.      *
  505.      * @access public
  506.      * @var string 
  507.      */
  508.     var $version;
  509.  
  510.     /**
  511.      * Uploaded file name
  512.      *
  513.      * @access public
  514.      * @var string 
  515.      */
  516.     var $file_src_name;
  517.  
  518.     /**
  519.      * Uploaded file name body (i.e. without extension)
  520.      *
  521.      * @access public
  522.      * @var string 
  523.      */
  524.     var $file_src_name_body;
  525.  
  526.     /**
  527.      * Uploaded file name extension
  528.      *
  529.      * @access public
  530.      * @var string 
  531.      */
  532.     var $file_src_name_ext;
  533.  
  534.     /**
  535.      * Uploaded file MIME type
  536.      *
  537.      * @access public
  538.      * @var string 
  539.      */
  540.     var $file_src_mime;
  541.  
  542.     /**
  543.      * Uploaded file size, in bytes
  544.      *
  545.      * @access public
  546.      * @var double 
  547.      */
  548.     var $file_src_size;
  549.  
  550.     /**
  551.      * Holds eventual PHP error code from $_FILES
  552.      *
  553.      * @access public
  554.      * @var string 
  555.      */
  556.     var $file_src_error;
  557.  
  558.     /**
  559.      * Uloaded file name, including server path
  560.      *
  561.      * @access private
  562.      * @var string 
  563.      */
  564.     var $file_src_pathname;
  565.  
  566.     /**
  567.      * Uloaded file name temporary copy
  568.      *
  569.      * @access private
  570.      * @var string 
  571.      */
  572.     var $file_src_temp;
  573.  
  574.     /**
  575.      * Destination file name
  576.      *
  577.      * @access private
  578.      * @var string 
  579.      */
  580.     var $file_dst_path;
  581.  
  582.     /**
  583.      * Destination file name
  584.      *
  585.      * @access public
  586.      * @var string 
  587.      */
  588.     var $file_dst_name;
  589.  
  590.     /**
  591.      * Destination file name body (i.e. without extension)
  592.      *
  593.      * @access public
  594.      * @var string 
  595.      */
  596.     var $file_dst_name_body;
  597.  
  598.     /**
  599.      * Destination file extension
  600.      *
  601.      * @access public
  602.      * @var string 
  603.      */
  604.     var $file_dst_name_ext;
  605.  
  606.     /**
  607.      * Destination file name, including path
  608.      *
  609.      * @access private
  610.      * @var string 
  611.      */
  612.     var $file_dst_pathname;
  613.  
  614.     /**
  615.      * Source image width
  616.      *
  617.      * @access private
  618.      * @var integer 
  619.      */
  620.     var $image_src_x;
  621.  
  622.     /**
  623.      * Source image height
  624.      *
  625.      * @access private
  626.      * @var integer 
  627.      */
  628.     var $image_src_y;
  629.  
  630.     /**
  631.      * Source image color depth
  632.      *
  633.      * @access private
  634.      * @var integer 
  635.      */
  636.     var $image_src_bits;
  637.  
  638.     /**
  639.      * Number of pixels
  640.      *
  641.      * @access private
  642.      * @var long 
  643.      */
  644.     var $image_src_pixels;
  645.  
  646.     /**
  647.      * Type of image (png, gif, jpg or bmp)
  648.      *
  649.      * @access private
  650.      * @var string 
  651.      */
  652.     var $image_src_type;
  653.  
  654.     /**
  655.      * Destination image width
  656.      *
  657.      * @access private
  658.      * @var integer 
  659.      */
  660.     var $image_dst_x;
  661.  
  662.     /**
  663.      * Destination image height
  664.      *
  665.      * @access private
  666.      * @var integer 
  667.      */
  668.     var $image_dst_y;
  669.  
  670.     /**
  671.      * Supported image formats
  672.      *
  673.      * @access private
  674.      * @var array 
  675.      */
  676.     var $image_supported;
  677.  
  678.     /**
  679.      * Flag to determine if the source file is an image
  680.      *
  681.      * @access private
  682.      * @var boolean 
  683.      */
  684.     var $file_is_image;
  685.  
  686.     /**
  687.      * Flag set after instanciating the class
  688.      *
  689.      * Indicates if the file has been uploaded properly
  690.      *
  691.      * @access public
  692.      * @var bool 
  693.      */
  694.     var $uploaded;
  695.  
  696.     /**
  697.      * Flag stopping PHP upload checks
  698.      *
  699.      * Indicates whether we instanciated the class with a filename, in which case
  700.      * we will not check on the validity of the PHP *upload*
  701.      *
  702.      * This flag is automatically set to true when working on a local file
  703.      *
  704.      * Warning: for uploads, this flag MUST be set to false for security reason
  705.      *
  706.      * @access public
  707.      * @var bool 
  708.      */
  709.     var $no_upload_check;
  710.  
  711.     /**
  712.      * Flag set after calling a process
  713.      *
  714.      * Indicates if the processing, and copy of the resulting file went OK
  715.      *
  716.      * @access public
  717.      * @var bool 
  718.      */
  719.     var $processed;
  720.  
  721.     /**
  722.      * Holds eventual error message in plain english
  723.      *
  724.      * @access public
  725.      * @var string 
  726.      */
  727.     var $error;
  728.  
  729.     /**
  730.      * Holds an HTML formatted log
  731.      *
  732.      * @access public
  733.      * @var string 
  734.      */
  735.     var $log;
  736.  
  737.  
  738.     // overiddable processing variables
  739.  
  740.  
  741.     /**
  742.      * Set this variable to replace the name body (i.e. without extension)
  743.      *
  744.      * @access public
  745.      * @var string 
  746.      */
  747.     var $file_new_name_body;
  748.  
  749.     /**
  750.      * Set this variable to add a string to the faile name body
  751.      *
  752.      * @access public
  753.      * @var string 
  754.      */
  755.     var $file_name_body_add;
  756.  
  757.     /**
  758.      * Set this variable to change the file extension
  759.      *
  760.      * @access public
  761.      * @var string 
  762.      */
  763.     var $file_new_name_ext;
  764.  
  765.     /**
  766.      * Set this variable to format the filename (spaces changed to _)
  767.      *
  768.      * @access public
  769.      * @var boolean 
  770.      */
  771.     var $file_safe_name;
  772.  
  773.     /**
  774.      * Set this variable to false if you don't want to check the MIME against the allowed list
  775.      *
  776.      * This variable is set to true by default for security reason
  777.      *
  778.      * @access public
  779.      * @var boolean 
  780.      */
  781.     var $mime_check;
  782.  
  783.     /**
  784.      * Set this variable to true if you want to check the MIME type against a mime_magic file
  785.      *
  786.      * This variable is set to false by default as many systems don't have mime_magic installed or properly set
  787.      *
  788.      * @access public
  789.      * @var boolean 
  790.      */
  791.     var $mime_magic_check;
  792.  
  793.     /**
  794.      * Set this variable to false if you don't want to turn dangerous scripts into simple text files
  795.      *
  796.      * @access public
  797.      * @var boolean 
  798.      */
  799.     var $no_script;
  800.  
  801.     /**
  802.      * Set this variable to true to allow automatic renaming of the file
  803.      * if the file already exists
  804.      *
  805.      * Default value is true
  806.      *
  807.      * For instance, on uploading foo.ext,<br>
  808.      * if foo.ext already exists, upload will be renamed foo_1.ext<br>
  809.      * and if foo_1.ext already exists, upload will be renamed foo_2.ext<br>
  810.      *
  811.      * @access public
  812.      * @var bool 
  813.      */
  814.     var $file_auto_rename;
  815.  
  816.     /**
  817.      * Set this variable to true to allow automatic creation of the destination
  818.      * directory if it is missing (works recursively)
  819.      *
  820.      * Default value is true
  821.      *
  822.      * @access public
  823.      * @var bool 
  824.      */
  825.     var $dir_auto_create;
  826.  
  827.     /**
  828.      * Set this variable to true to allow automatic chmod of the destination
  829.      * directory if it is not writeable
  830.      *
  831.      * Default value is true
  832.      *
  833.      * @access public
  834.      * @var bool 
  835.      */
  836.     var $dir_auto_chmod;
  837.  
  838.     /**
  839.      * Set this variable to the default chmod you want the class to use
  840.      * when creating directories, or attempting to write in a directory
  841.      *
  842.      * Default value is 0777 (without quotes)
  843.      *
  844.      * @access public
  845.      * @var bool 
  846.      */
  847.     var $dir_chmod;
  848.  
  849.     /**
  850.      * Set this variable tu true to allow overwriting of an existing file
  851.      *
  852.      * Default value is false, so no files will be overwritten
  853.      *
  854.      * @access public
  855.      * @var bool 
  856.      */
  857.     var $file_overwrite;
  858.  
  859.     /**
  860.      * Set this variable to change the maximum size in bytes for an uploaded file
  861.      *
  862.      * Default value is the value <i>upload_max_filesize</i> from php.ini
  863.      *
  864.      * @access public
  865.      * @var double 
  866.      */
  867.     var $file_max_size;
  868.  
  869.     /**
  870.      * Set this variable to true to resize the file if it is an image
  871.      *
  872.      * You will probably want to set {@link image_x} and {@link image_y}, and maybe one of the ratio variables
  873.      *
  874.      * Default value is false (no resizing)
  875.      *
  876.      * @access public
  877.      * @var bool 
  878.      */
  879.     var $image_resize;
  880.  
  881.     /**
  882.      * Set this variable to convert the file if it is an image
  883.      *
  884.      * Possibles values are : ''; 'png'; 'jpeg'; 'gif'; 'bmp'
  885.      *
  886.      * Default value is '' (no conversion)<br>
  887.      * If {@link resize} is true, {@link convert} will be set to the source file extension
  888.      *
  889.      * @access public
  890.      * @var string 
  891.      */
  892.     var $image_convert;
  893.  
  894.     /**
  895.      * Set this variable to the wanted (or maximum/minimum) width for the processed image, in pixels
  896.      *
  897.      * Default value is 150
  898.      *
  899.      * @access public
  900.      * @var integer 
  901.      */
  902.     var $image_x;
  903.  
  904.     /**
  905.      * Set this variable to the wanted (or maximum/minimum) height for the processed image, in pixels
  906.      *
  907.      * Default value is 150
  908.      *
  909.      * @access public
  910.      * @var integer 
  911.      */
  912.     var $image_y;
  913.  
  914.     /**
  915.      * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}
  916.      *
  917.      * Default value is false
  918.      *
  919.      * @access public
  920.      * @var bool 
  921.      */
  922.     var $image_ratio;
  923.  
  924.     /**
  925.      * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}
  926.      *
  927.      * The image will be resized as to fill the whole space, and excedent will be cropped
  928.      *
  929.      * Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right)
  930.      * If set as a string, it determines which side of the image is kept while cropping.
  931.      * By default, the part of the image kept is in the center, i.e. it crops equally on both sides
  932.      *
  933.      * Default value is false
  934.      *
  935.      * @access public
  936.      * @var mixed 
  937.      */
  938.     var $image_ratio_crop;
  939.  
  940.     /**
  941.      * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y}
  942.      *
  943.      * The image will be resized to fit entirely in the space, and the rest will be colored.
  944.      * The default color is white, but can be set with {@link image_default_color}
  945.      *
  946.      * Value can also be a string, one or more character from 'TBLR' (top, bottom, left and right)
  947.      * If set as a string, it determines in which side of the space the image is displayed.
  948.      * By default, the image is displayed in the center, i.e. it fills the remaining space equally on both sides
  949.      *
  950.      * Default value is false
  951.      *
  952.      * @access public
  953.      * @var mixed 
  954.      */
  955.     var $image_ratio_fill;
  956.  
  957.     /**
  958.      * Set this variable to a number of pixels so that {@link image_x} and {@link image_y} are the best match possible
  959.      *
  960.      * The image will be resized to have approximatively the number of pixels
  961.      * The aspect ratio wil be conserved
  962.      *
  963.      * Default value is false
  964.      *
  965.      * @access public
  966.      * @var mixed 
  967.      */
  968.     var $image_ratio_pixels;
  969.  
  970.     /**
  971.      * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y},
  972.      * but only if original image is bigger
  973.      *
  974.      * Default value is false
  975.      *
  976.      * @access public
  977.      * @var bool 
  978.      */
  979.  
  980.     /**
  981.      * Set this variable to keep the original size ratio to fit within {@link image_x} x {@link image_y},
  982.      * but only if original image is smaller
  983.      *
  984.      * Default value is false
  985.      *
  986.      * @access public
  987.      * @var bool 
  988.      */
  989.  
  990.     /**
  991.      * Set this variable to calculate {@link image_x} automatically , using {@link image_y} and conserving ratio
  992.      *
  993.      * Default value is false
  994.      *
  995.      * @access public
  996.      * @var bool 
  997.      */
  998.     var $image_ratio_x;
  999.  
  1000.     /**
  1001.      * Set this variable to calculate {@link image_y} automatically , using {@link image_x} and conserving ratio
  1002.      *
  1003.      * Default value is false
  1004.      *
  1005.      * @access public
  1006.      * @var bool 
  1007.      */
  1008.     var $image_ratio_y;
  1009.  
  1010.     /**
  1011.      * Set this variable to set a maximum image width, above which the upload will be invalid
  1012.      *
  1013.      * Default value is null
  1014.      *
  1015.      * @access public
  1016.      * @var integer 
  1017.      */
  1018.     var $image_max_width;
  1019.  
  1020.     /**
  1021.      * Set this variable to set a maximum image height, above which the upload will be invalid
  1022.      *
  1023.      * Default value is null
  1024.      *
  1025.      * @access public
  1026.      * @var integer 
  1027.      */
  1028.     var $image_max_height;
  1029.  
  1030.     /**
  1031.      * Set this variable to set a maximum number of pixels for an image, above which the upload will be invalid
  1032.      *
  1033.      * Default value is null
  1034.      *
  1035.      * @access public
  1036.      * @var long 
  1037.      */
  1038.     var $image_max_pixels;
  1039.  
  1040.     /**
  1041.      * Set this variable to set a maximum image aspect ratio, above which the upload will be invalid
  1042.      *
  1043.      * Note that ratio = width / height
  1044.      *
  1045.      * Default value is null
  1046.      *
  1047.      * @access public
  1048.      * @var float 
  1049.      */
  1050.     var $image_max_ratio;
  1051.  
  1052.     /**
  1053.      * Set this variable to set a minimum image width, below which the upload will be invalid
  1054.      *
  1055.      * Default value is null
  1056.      *
  1057.      * @access public
  1058.      * @var integer 
  1059.      */
  1060.     var $image_min_width;
  1061.  
  1062.     /**
  1063.      * Set this variable to set a minimum image height, below which the upload will be invalid
  1064.      *
  1065.      * Default value is null
  1066.      *
  1067.      * @access public
  1068.      * @var integer 
  1069.      */
  1070.     var $image_min_height;
  1071.  
  1072.     /**
  1073.      * Set this variable to set a minimum number of pixels for an image, below which the upload will be invalid
  1074.      *
  1075.      * Default value is null
  1076.      *
  1077.      * @access public
  1078.      * @var long 
  1079.      */
  1080.     var $image_min_pixels;
  1081.  
  1082.     /**
  1083.      * Set this variable to set a minimum image aspect ratio, below which the upload will be invalid
  1084.      *
  1085.      * Note that ratio = width / height
  1086.      *
  1087.      * Default value is null
  1088.      *
  1089.      * @access public
  1090.      * @var float 
  1091.      */
  1092.     var $image_min_ratio;
  1093.  
  1094.     /**
  1095.      * Quality of JPEG created/converted destination image
  1096.      *
  1097.      * Default value is 85
  1098.      *
  1099.      * @access public
  1100.      * @var integer 
  1101.      */
  1102.     var $jpeg_quality;
  1103.  
  1104.     /**
  1105.      * Determines the quality of the JPG image to fit a desired file size
  1106.      *
  1107.      * Value is in bytes. The JPG quality will be set between 1 and 100%
  1108.      * The calculations are approximations.
  1109.      *
  1110.      * Default value is null (no calculations)
  1111.      *
  1112.      * @access public
  1113.      * @var integer 
  1114.      */
  1115.     var $jpeg_size;
  1116.  
  1117.     /**
  1118.      * Preserve transparency when resizing or converting an image (deprecated)
  1119.      *
  1120.      * Default value is automatically set to true for transparent GIFs
  1121.      * This setting is now deprecated
  1122.      *
  1123.      * @access public
  1124.      * @var integer 
  1125.      */
  1126.  
  1127.     /**
  1128.      * Flag set to true when the image is transparent
  1129.      *
  1130.      * This is actually used only for transparent GIFs
  1131.      *
  1132.      * @access public
  1133.      * @var boolean 
  1134.      */
  1135.     var $image_is_transparent;
  1136.  
  1137.     /**
  1138.      * Transparent color in a palette
  1139.      *
  1140.      * This is actually used only for transparent GIFs
  1141.      *
  1142.      * @access public
  1143.      * @var boolean 
  1144.      */
  1145.  
  1146.     /**
  1147.      * Background color, used to paint transparent areas with
  1148.      *
  1149.      * If set, it will forcibly remove transparency by painting transparent areas with the color
  1150.      * This setting will fill in all transparent areas in PNG and GIF, as opposed to {@link image_default_color}
  1151.      * which will do so only in BMP, JPEG, and alpha transparent areas in transparent GIFs
  1152.      * This setting overrides {@link image_default_color}
  1153.      *
  1154.      * Default value is null
  1155.      *
  1156.      * @access public
  1157.      * @var string 
  1158.      */
  1159.  
  1160.     /**
  1161.      * Default color for non alpha-transparent images
  1162.      *
  1163.      * This setting is to be used to define a background color for semi transparent areas
  1164.      * of an alpha transparent when the output format doesn't support alpha transparency
  1165.      * This is useful when, from an alpha transparent PNG image, or an image with alpha transparent features
  1166.      * if you want to output it as a transparent GIFs for instance, you can set a blending color for transparent areas
  1167.      * If you output in JPEG or BMP, this color will be used to fill in the previously transparent areas
  1168.      *
  1169.      * The default color white
  1170.      *
  1171.      * @access public
  1172.      * @var boolean 
  1173.      */
  1174.     var $image_default_color;
  1175.  
  1176.     /**
  1177.      * Flag set to true when the image is not true color
  1178.      *
  1179.      * @access public
  1180.      * @var boolean 
  1181.      */
  1182.     var $image_is_palette;
  1183.  
  1184.     /**
  1185.      * Corrects the image brightness
  1186.      *
  1187.      * Value can range between -127 and 127
  1188.      *
  1189.      * Default value is null
  1190.      *
  1191.      * @access public
  1192.      * @var integer 
  1193.      */
  1194.     var $image_brightness;
  1195.  
  1196.     /**
  1197.      * Corrects the image contrast
  1198.      *
  1199.      * Value can range between -127 and 127
  1200.      *
  1201.      * Default value is null
  1202.      *
  1203.      * @access public
  1204.      * @var integer 
  1205.      */
  1206.     var $image_contrast;
  1207.  
  1208.     /**
  1209.      * Applies threshold filter
  1210.      *
  1211.      * Value can range between -127 and 127
  1212.      *
  1213.      * Default value is null
  1214.      *
  1215.      * @access public
  1216.      * @var integer 
  1217.      */
  1218.     var $image_threshold;
  1219.  
  1220.     /**
  1221.      * Applies a tint on the image
  1222.      *
  1223.      * Value is an hexadecimal color, such as #FFFFFF
  1224.      *
  1225.      * Default value is null
  1226.      *
  1227.      * @access public
  1228.      * @var string; 
  1229.      */
  1230.     var $image_tint_color;
  1231.  
  1232.     /**
  1233.      * Applies a colored overlay on the image
  1234.      *
  1235.      * Value is an hexadecimal color, such as #FFFFFF
  1236.      *
  1237.      * To use with {@link image_overlay_percent}
  1238.      *
  1239.      * Default value is null
  1240.      *
  1241.      * @access public
  1242.      * @var string; 
  1243.      */
  1244.     var $image_overlay_color;
  1245.  
  1246.     /**
  1247.      * Sets the percentage for the colored overlay
  1248.      *
  1249.      * Value is a percentage, as an integer between 0 and 100
  1250.      *
  1251.      * Unless used with {@link image_overlay_color}, this setting has no effect
  1252.      *
  1253.      * Default value is 50
  1254.      *
  1255.      * @access public
  1256.      * @var integer 
  1257.      */
  1258.  
  1259.     /**
  1260.      * Inverts the color of an image
  1261.      *
  1262.      * Default value is FALSE
  1263.      *
  1264.      * @access public
  1265.      * @var boolean; 
  1266.      */
  1267.     var $image_negative;
  1268.  
  1269.     /**
  1270.      * Turns the image into greyscale
  1271.      *
  1272.      * Default value is FALSE
  1273.      *
  1274.      * @access public
  1275.      * @var boolean; 
  1276.      */
  1277.     var $image_greyscale;
  1278.  
  1279.     /**
  1280.      * Adds a text label on the image
  1281.      *
  1282.      * Value is a string, any text. Text will not word-wrap, although you can use breaklines in your text "\n"
  1283.      *
  1284.      * If set, this setting allow the use of all other settings starting with image_text_
  1285.      *
  1286.      * Replacement tokens can be used in the string:
  1287.      * <pre>
  1288.      * gd_version    src_name       src_name_body src_name_ext
  1289.      * src_pathname  src_mime       src_x         src_y
  1290.      * src_type      src_bits       src_pixels
  1291.      * src_size      src_size_kb    src_size_mb   src_size_human
  1292.      * dst_path      dst_name_body  dst_pathname
  1293.      * dst_name      dst_name_ext   dst_x         dst_y
  1294.      * date          time           host          server        ip
  1295.      * </pre>
  1296.      * The tokens must be enclosed in square brackets: [dst_x] will be replaced by the width of the picture
  1297.      *
  1298.      * Default value is null
  1299.      *
  1300.      * @access public
  1301.      * @var string; 
  1302.      */
  1303.     var $image_text;
  1304.  
  1305.     /**
  1306.      * Sets the text direction for the text label
  1307.      *
  1308.      * Value is either 'h' or 'v', as in horizontal and vertical
  1309.      *
  1310.      * Default value is h (horizontal)
  1311.      *
  1312.      * @access public
  1313.      * @var string; 
  1314.      */
  1315.     var $image_text_direction;
  1316.  
  1317.     /**
  1318.      * Sets the text color for the text label
  1319.      *
  1320.      * Value is an hexadecimal color, such as #FFFFFF
  1321.      *
  1322.      * Default value is #FFFFFF (white)
  1323.      *
  1324.      * @access public
  1325.      * @var string; 
  1326.      */
  1327.     var $image_text_color;
  1328.  
  1329.     /**
  1330.      * Sets the text visibility in the text label
  1331.      *
  1332.      * Value is a percentage, as an integer between 0 and 100
  1333.      *
  1334.      * Default value is 100
  1335.      *
  1336.      * @access public
  1337.      * @var integer 
  1338.      */
  1339.     var $image_text_percent;
  1340.  
  1341.     /**
  1342.      * Sets the text background color for the text label
  1343.      *
  1344.      * Value is an hexadecimal color, such as #FFFFFF
  1345.      *
  1346.      * Default value is null (no background)
  1347.      *
  1348.      * @access public
  1349.      * @var string; 
  1350.      */
  1351.  
  1352.     /**
  1353.      * Sets the text background visibility in the text label
  1354.      *
  1355.      * Value is a percentage, as an integer between 0 and 100
  1356.      *
  1357.      * Default value is 100
  1358.      *
  1359.      * @access public
  1360.      * @var integer 
  1361.      */
  1362.  
  1363.     /**
  1364.      * Sets the text font in the text label
  1365.      *
  1366.      * Value is a an integer between 1 and 5 for GD built-in fonts. 1 is the smallest font, 5 the biggest
  1367.      * 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.
  1368.      *
  1369.      * Default value is 5
  1370.      *
  1371.      * @access public
  1372.      * @var mixed; 
  1373.      */
  1374.     var $image_text_font;
  1375.  
  1376.     /**
  1377.      * Sets the text label position within the image
  1378.      *
  1379.      * Value is one or two out of 'TBLR' (top, bottom, left, right)
  1380.      *
  1381.      * The positions are as following:
  1382.      * <pre>
  1383.      *                        TL  T  TR
  1384.      *                        L       R
  1385.      *                        BL  B  BR
  1386.      * </pre>
  1387.      *
  1388.      * Default value is null (centered, horizontal and vertical)
  1389.      *
  1390.      * Note that is {@link image_text_x} and {@link image_text_y} are used, this setting has no effect
  1391.      *
  1392.      * @access public
  1393.      * @var string; 
  1394.      */
  1395.     var $image_text_position;
  1396.  
  1397.     /**
  1398.      * Sets the text label absolute X position within the image
  1399.      *
  1400.      * Value is in pixels, representing the distance between the left of the image and the label
  1401.      * If a negative value is used, it will represent the distance between the right of the image and the label
  1402.      *
  1403.      * Default value is null (so {@link image_text_position} is used)
  1404.      *
  1405.      * @access public
  1406.      * @var integer 
  1407.      */
  1408.     var $image_text_x;
  1409.  
  1410.     /**
  1411.      * Sets the text label absolute Y position within the image
  1412.      *
  1413.      * Value is in pixels, representing the distance between the top of the image and the label
  1414.      * If a negative value is used, it will represent the distance between the bottom of the image and the label
  1415.      *
  1416.      * Default value is null (so {@link image_text_position} is used)
  1417.      *
  1418.      * @access public
  1419.      * @var integer 
  1420.      */
  1421.     var $image_text_y;
  1422.  
  1423.     /**
  1424.      * Sets the text label padding
  1425.      *
  1426.      * Value is in pixels, representing the distance between the text and the label background border
  1427.      *
  1428.      * Default value is 0
  1429.      *
  1430.      * This setting can be overriden by {@link image_text_padding_x} and {@link image_text_padding_y}
  1431.      *
  1432.      * @access public
  1433.      * @var integer 
  1434.      */
  1435.     var $image_text_padding;
  1436.  
  1437.     /**
  1438.      * Sets the text label horizontal padding
  1439.      *
  1440.      * Value is in pixels, representing the distance between the text and the left and right label background borders
  1441.      *
  1442.      * Default value is null
  1443.      *
  1444.      * If set, this setting overrides the horizontal part of {@link image_text_padding}
  1445.      *
  1446.      * @access public
  1447.      * @var integer 
  1448.      */
  1449.     var $image_text_padding_x;
  1450.  
  1451.     /**
  1452.      * Sets the text label vertical padding
  1453.      *
  1454.      * Value is in pixels, representing the distance between the text and the top and bottom label background borders
  1455.      *
  1456.      * Default value is null
  1457.      *
  1458.      * If set, his setting overrides the vertical part of {@link image_text_padding}
  1459.      *
  1460.      * @access public
  1461.      * @var integer 
  1462.      */
  1463.     var $image_text_padding_y;
  1464.  
  1465.     /**
  1466.      * Sets the text alignment
  1467.      *
  1468.      * Value is a string, which can be either 'L', 'C' or 'R'
  1469.      *
  1470.      * Default value is 'C'
  1471.      *
  1472.      * This setting is relevant only if the text has several lines.
  1473.      *
  1474.      * @access public
  1475.      * @var string; 
  1476.      */
  1477.     var $image_text_alignment;
  1478.  
  1479.     /**
  1480.      * Sets the text line spacing
  1481.      *
  1482.      * Value is an integer, in pixels
  1483.      *
  1484.      * Default value is 0
  1485.      *
  1486.      * This setting is relevant only if the text has several lines.
  1487.      *
  1488.      * @access public
  1489.      * @var integer 
  1490.      */
  1491.  
  1492.     /**
  1493.      * Sets the height of the reflection
  1494.      *
  1495.      * Value is an integer in pixels, or a string which format can be in pixels or percentage.
  1496.      * For instance, values can be : 40, '40', '40px' or '40%'
  1497.      *
  1498.      * Default value is null, no reflection
  1499.      *
  1500.      * @access public
  1501.      * @var mixed; 
  1502.      */
  1503.  
  1504.     /**
  1505.      * Sets the space between the source image and its relection
  1506.      *
  1507.      * Value is an integer in pixels, which can be negative
  1508.      *
  1509.      * Default value is 2
  1510.      *
  1511.      * This setting is relevant only if {@link image_reflection_height} is set
  1512.      *
  1513.      * @access public
  1514.      * @var integer 
  1515.      */
  1516.  
  1517.     /**
  1518.      * Sets the color of the reflection background (deprecated)
  1519.      *
  1520.      * Value is an hexadecimal color, such as #FFFFFF
  1521.      *
  1522.      * Default value is #FFFFFF
  1523.      *
  1524.      * This setting is relevant only if {@link image_reflection_height} is set
  1525.      *
  1526.      * This setting is now deprecated in favor of {@link image_default_color}
  1527.      *
  1528.      * @access public
  1529.      * @var string; 
  1530.      */
  1531.  
  1532.     /**
  1533.      * Sets the initial opacity of the reflection
  1534.      *
  1535.      * Value is an integer between 0 (no opacity) and 100 (full opacity).
  1536.      * The reflection will start from {@link image_reflection_opacity} and end up at 0
  1537.      *
  1538.      * Default value is 60
  1539.      *
  1540.      * This setting is relevant only if {@link image_reflection_height} is set
  1541.      *
  1542.      * @access public
  1543.      * @var integer 
  1544.      */
  1545.  
  1546.     /**
  1547.      * Flips the image vertically or horizontally
  1548.      *
  1549.      * Value is either 'h' or 'v', as in horizontal and vertical
  1550.      *
  1551.      * Default value is null (no flip)
  1552.      *
  1553.      * @access public
  1554.      * @var string; 
  1555.      */
  1556.     var $image_flip;
  1557.  
  1558.     /**
  1559.      * Rotates the image by increments of 45 degrees
  1560.      *
  1561.      * Value is either 90, 180 or 270
  1562.      *
  1563.      * Default value is null (no rotation)
  1564.      *
  1565.      * @access public
  1566.      * @var string; 
  1567.      */
  1568.     var $image_rotate;
  1569.  
  1570.     /**
  1571.      * Crops an image
  1572.      *
  1573.      * Values are four dimensions, or two, or one (CSS style)
  1574.      * They represent the amount cropped top, right, bottom and left.
  1575.      * These values can either be in an array, or a space separated string.
  1576.      * Each value can be in pixels (with or without 'px'), or percentage (of the source image)
  1577.      *
  1578.      * For instance, are valid:
  1579.      * <pre>
  1580.      * $foo->image_crop = 20                  OR array(20);
  1581.      * $foo->image_crop = '20px'              OR array('20px');
  1582.      * $foo->image_crop = '20 40'             OR array('20', 40);
  1583.      * $foo->image_crop = '-20 25%'           OR array(-20, '25%');
  1584.      * $foo->image_crop = '20px 25%'          OR array('20px', '25%');
  1585.      * $foo->image_crop = '20% 25%'           OR array('20%', '25%');
  1586.      * $foo->image_crop = '20% 25% 10% 30%'   OR array('20%', '25%', '10%', '30%');
  1587.      * $foo->image_crop = '20px 25px 2px 2px' OR array('20px', '25%px', '2px', '2px');
  1588.      * $foo->image_crop = '20 25% 40px 10%'   OR array(20, '25%', '40px', '10%');
  1589.      * </pre>
  1590.      *
  1591.      * If a value is negative, the image will be expanded, and the extra parts will be filled with black
  1592.      *
  1593.      * Default value is null (no cropping)
  1594.      *
  1595.      * @access public
  1596.      * @var string OR array;
  1597.      */
  1598.     var $image_crop;
  1599.  
  1600.     /**
  1601.      * Adds a bevel border on the image
  1602.      *
  1603.      * Value is a positive integer, representing the thickness of the bevel
  1604.      *
  1605.      * If the bevel colors are the same as the background, it makes a fade out effect
  1606.      *
  1607.      * Default value is null (no bevel)
  1608.      *
  1609.      * @access public
  1610.      * @var integer 
  1611.      */
  1612.     var $image_bevel;
  1613.  
  1614.     /**
  1615.      * Top and left bevel color
  1616.      *
  1617.      * Value is a color, in hexadecimal format
  1618.      * This setting is used only if {@link image_bevel} is set
  1619.      *
  1620.      * Default value is #FFFFFF
  1621.      *
  1622.      * @access public
  1623.      * @var string; 
  1624.      */
  1625.     var $image_bevel_color1;
  1626.  
  1627.     /**
  1628.      * Right and bottom bevel color
  1629.      *
  1630.      * Value is a color, in hexadecimal format
  1631.      * This setting is used only if {@link image_bevel} is set
  1632.      *
  1633.      * Default value is #000000
  1634.      *
  1635.      * @access public
  1636.      * @var string; 
  1637.      */
  1638.     var $image_bevel_color2;
  1639.  
  1640.     /**
  1641.      * Adds a single-color border on the outer of the image
  1642.      *
  1643.      * Values are four dimensions, or two, or one (CSS style)
  1644.      * They represent the border thickness top, right, bottom and left.
  1645.      * These values can either be in an array, or a space separated string.
  1646.      * Each value can be in pixels (with or without 'px'), or percentage (of the source image)
  1647.      *
  1648.      * See {@link image_crop} for valid formats
  1649.      *
  1650.      * If a value is negative, the image will be cropped.
  1651.      * Note that the dimensions of the picture will be increased by the borders' thickness
  1652.      *
  1653.      * Default value is null (no border)
  1654.      *
  1655.      * @access public
  1656.      * @var integer 
  1657.      */
  1658.     var $image_border;
  1659.  
  1660.     /**
  1661.      * Border color
  1662.      *
  1663.      * Value is a color, in hexadecimal format.
  1664.      * This setting is used only if {@link image_border} is set
  1665.      *
  1666.      * Default value is #FFFFFF
  1667.      *
  1668.      * @access public
  1669.      * @var string; 
  1670.      */
  1671.     var $image_border_color;
  1672.  
  1673.     /**
  1674.      * Adds a multi-color frame on the outer of the image
  1675.      *
  1676.      * Value is an integer. Two values are possible for now:
  1677.      * 1 for flat border, meaning that the frame is mirrored horizontally and vertically
  1678.      * 2 for crossed border, meaning that the frame will be inversed, as in a bevel effect
  1679.      *
  1680.      * The frame will be composed of colored lines set in {@link image_frame_colors}
  1681.      *
  1682.      * Note that the dimensions of the picture will be increased by the borders' thickness
  1683.      *
  1684.      * Default value is null (no frame)
  1685.      *
  1686.      * @access public
  1687.      * @var integer 
  1688.      */
  1689.     var $image_frame;
  1690.  
  1691.     /**
  1692.      * Sets the colors used to draw a frame
  1693.      *
  1694.      * Values is a list of n colors in hexadecimal format.
  1695.      * These values can either be in an array, or a space separated string.
  1696.      *
  1697.      * The colors are listed in the following order: from the outset of the image to its center
  1698.      *
  1699.      * For instance, are valid:
  1700.      * <pre>
  1701.      * $foo->image_frame_colors = '#FFFFFF #999999 #666666 #000000';
  1702.      * $foo->image_frame_colors = array('#FFFFFF', '#999999', '#666666', '#000000');
  1703.      * </pre>
  1704.      *
  1705.      * This setting is used only if {@link image_frame} is set
  1706.      *
  1707.      * Default value is '#FFFFFF #999999 #666666 #000000'
  1708.      *
  1709.      * @access public
  1710.      * @var string OR array;
  1711.      */
  1712.     var $image_frame_colors;
  1713.  
  1714.     /**
  1715.      * Adds a watermark on the image
  1716.      *
  1717.      * Value is a local image filename, relative or absolute. GIF, JPG, BMP and PNG are supported, as well as PNG alpha.
  1718.      *
  1719.      * If set, this setting allow the use of all other settings starting with image_watermark_
  1720.      *
  1721.      * Default value is null
  1722.      *
  1723.      * @access public
  1724.      * @var string; 
  1725.      */
  1726.     var $image_watermark;
  1727.  
  1728.     /**
  1729.      * Sets the watermarkposition within the image
  1730.      *
  1731.      * Value is one or two out of 'TBLR' (top, bottom, left, right)
  1732.      *
  1733.      * The positions are as following:   TL  T  TR
  1734.      *                                   L       R
  1735.      *                                   BL  B  BR
  1736.      *
  1737.      * Default value is null (centered, horizontal and vertical)
  1738.      *
  1739.      * Note that is {@link image_watermark_x} and {@link image_watermark_y} are used, this setting has no effect
  1740.      *
  1741.      * @access public
  1742.      * @var string; 
  1743.      */
  1744.  
  1745.     /**
  1746.      * Sets the watermark absolute X position within the image
  1747.      *
  1748.      * Value is in pixels, representing the distance between the top of the image and the watermark
  1749.      * If a negative value is used, it will represent the distance between the bottom of the image and the watermark
  1750.      *
  1751.      * Default value is null (so {@link image_watermark_position} is used)
  1752.      *
  1753.      * @access public
  1754.      * @var integer 
  1755.      */
  1756.     var $image_watermark_x;
  1757.  
  1758.     /**
  1759.      * Sets the twatermark absolute Y position within the image
  1760.      *
  1761.      * Value is in pixels, representing the distance between the left of the image and the watermark
  1762.      * If a negative value is used, it will represent the distance between the right of the image and the watermark
  1763.      *
  1764.      * Default value is null (so {@link image_watermark_position} is used)
  1765.      *
  1766.      * @access public
  1767.      * @var integer 
  1768.      */
  1769.     var $image_watermark_y;
  1770.  
  1771.     /**
  1772.      * Allowed MIME types
  1773.      *
  1774.      * Default is a selection of safe mime-types, but you might want to change it
  1775.      *
  1776.      * Simple wildcards are allowed, such as image/* or application/*
  1777.      *
  1778.      * @access public
  1779.      * @var array 
  1780.      */
  1781.     var $allowed;
  1782.  
  1783.     /**
  1784.      * Forbidden MIME types
  1785.      *
  1786.      * Default is a selection of safe mime-types, but you might want to change it
  1787.      * To only check for forbidden MIME types, and allow everything else, set {@link allowed} to array('* / *') without the spaces
  1788.      *
  1789.      * Simple wildcards are allowed, such as image/* or application/*
  1790.      *
  1791.      * @access public
  1792.      * @var array 
  1793.      */
  1794.     var $forbidden;
  1795.  
  1796.     /**
  1797.      * Array of translated error messages
  1798.      *
  1799.      * By default, the language is english (en_GB)
  1800.      * Translations can be in separate files, in a lang/ subdirectory
  1801.      *
  1802.      * @access public
  1803.      * @var array 
  1804.      */
  1805.     var $translation;
  1806.  
  1807.     /**
  1808.      * Language selected for the translations
  1809.      *
  1810.      * By default, the language is english ("en_GB")
  1811.      *
  1812.      * @access public
  1813.      * @var array 
  1814.      */
  1815.     var $language;
  1816.  
  1817.     /**
  1818.      * Init or re-init all the processing variables to their default values
  1819.      *
  1820.      * This function is called in the constructor, and after each call of {@link process}
  1821.      *
  1822.      * @access private
  1823.      */
  1824.     function init({
  1825.  
  1826.         // overiddable variables
  1827.         $this->file_new_name_body       = '';       // replace the name body
  1828.         $this->file_name_body_add       = '';       // append to the name body
  1829.         $this->file_new_name_ext        = '';       // replace the file extension
  1830.         $this->file_safe_name           = true;     // format safely the filename
  1831.         $this->file_overwrite           = false;    // allows overwritting if the file already exists
  1832.         $this->file_auto_rename         = true;     // auto-rename if the file already exists
  1833.         $this->dir_auto_create          = true;     // auto-creates directory if missing
  1834.         $this->dir_auto_chmod           = true;     // auto-chmod directory if not writeable
  1835.         $this->dir_chmod                = 0777;     // default chmod to use
  1836.  
  1837.         $this->mime_check               = true;     // don't check the mime type against the allowed list
  1838.         $this->mime_magic_check         = false;    // don't double check the MIME type with mime_magic
  1839.         $this->no_script                = true;     // turns scripts into test files
  1840.  
  1841.         $val trim(ini_get('upload_max_filesize'));
  1842.         $last strtolower($val{strlen($val)-1});
  1843.         switch($last{
  1844.             case 'g':
  1845.                 $val *= 1024;
  1846.             case 'm':
  1847.                 $val *= 1024;
  1848.             case 'k':
  1849.                 $val *= 1024;
  1850.         }
  1851.         $this->file_max_size = $val;
  1852.  
  1853.         $this->image_resize             = false;    // resize the image
  1854.         $this->image_convert            = '';       // convert. values :''; 'png'; 'jpeg'; 'gif'; 'bmp'
  1855.  
  1856.         $this->image_x                  = 150;
  1857.         $this->image_y                  = 150;
  1858.         $this->image_ratio              = false;    // keeps aspect ratio with x and y dimensions
  1859.         $this->image_ratio_crop         = false;    // keeps aspect ratio with x and y dimensions, filling the space
  1860.         $this->image_ratio_fill         = false;    // keeps aspect ratio with x and y dimensions, fitting the image in the space, and coloring the rest
  1861.         $this->image_ratio_pixels       = false;    // keeps aspect ratio, calculating x and y so that the image is approx the set number of pixels
  1862.         $this->image_ratio_no_zoom_in   = false;
  1863.         $this->image_ratio_no_zoom_out  = false;
  1864.         $this->image_ratio_x            = false;    // calculate the $image_x if true
  1865.         $this->image_ratio_y            = false;    // calculate the $image_y if true
  1866.         $this->jpeg_quality             = 85;
  1867.         $this->jpeg_size                = null;
  1868.         $this->preserve_transparency    = false;
  1869.         $this->image_is_transparent     = false;
  1870.         $this->image_transparent_color  = null;
  1871.         $this->image_background_color   = null;
  1872.         $this->image_default_color      = '#ffffff';
  1873.         $this->image_is_palette         = false;
  1874.  
  1875.         $this->image_max_width          = null;
  1876.         $this->image_max_height         = null;
  1877.         $this->image_max_pixels         = null;
  1878.         $this->image_max_ratio          = null;
  1879.         $this->image_min_width          = null;
  1880.         $this->image_min_height         = null;
  1881.         $this->image_min_pixels         = null;
  1882.         $this->image_min_ratio          = null;
  1883.  
  1884.         $this->image_brightness         = null;
  1885.         $this->image_contrast           = null;
  1886.         $this->image_threshold          = null;
  1887.         $this->image_tint_color         = null;
  1888.         $this->image_overlay_color      = null;
  1889.         $this->image_overlay_percent    = null;
  1890.         $this->image_negative           = false;
  1891.         $this->image_greyscale          = false;
  1892.  
  1893.         $this->image_text               = null;
  1894.         $this->image_text_direction     = null;
  1895.         $this->image_text_color         = '#FFFFFF';
  1896.         $this->image_text_percent       = 100;
  1897.         $this->image_text_background    = null;
  1898.         $this->image_text_background_percent = 100;
  1899.         $this->image_text_font          = 5;
  1900.         $this->image_text_x             = null;
  1901.         $this->image_text_y             = null;
  1902.         $this->image_text_position      = null;
  1903.         $this->image_text_padding       = 0;
  1904.         $this->image_text_padding_x     = null;
  1905.         $this->image_text_padding_y     = null;
  1906.         $this->image_text_alignment     = 'C';
  1907.         $this->image_text_line_spacing  = 0;
  1908.  
  1909.         $this->image_reflection_height  = null;
  1910.         $this->image_reflection_space   = 2;
  1911.         $this->image_reflection_color   = '#ffffff';
  1912.         $this->image_reflection_opacity = 60;
  1913.  
  1914.         $this->image_watermark          = null;
  1915.         $this->image_watermark_x        = null;
  1916.         $this->image_watermark_y        = null;
  1917.         $this->image_watermark_position = null;
  1918.  
  1919.         $this->image_flip               = null;
  1920.         $this->image_rotate             = null;
  1921.         $this->image_crop               = null;
  1922.  
  1923.         $this->image_bevel              = null;
  1924.         $this->image_bevel_color1       = '#FFFFFF';
  1925.         $this->image_bevel_color2       = '#000000';
  1926.         $this->image_border             = null;
  1927.         $this->image_border_color       = '#FFFFFF';
  1928.         $this->image_frame              = null;
  1929.         $this->image_frame_colors       = '#FFFFFF #999999 #666666 #000000';
  1930.  
  1931.         $this->forbidden = array();
  1932.         $this->allowed = array("application/rar",
  1933.                                "application/x-rar-compressed",
  1934.                                "application/arj",
  1935.                                "application/excel",
  1936.                                "application/gnutar",
  1937.                                "application/octet-stream",
  1938.                                "application/pdf",
  1939.                                "application/powerpoint",
  1940.                                "application/postscript",
  1941.                                "application/plain",
  1942.                                "application/rtf",
  1943.                                "application/vocaltec-media-file",
  1944.                                "application/wordperfect",
  1945.                                "application/x-bzip",
  1946.                                "application/x-bzip2",
  1947.                                "application/x-compressed",
  1948.                                "application/x-excel",
  1949.                                "application/x-gzip",
  1950.                                "application/x-latex",
  1951.                                "application/x-midi",
  1952.                                "application/x-msexcel",
  1953.                                "application/x-rtf",
  1954.                                "application/x-sit",
  1955.                                "application/x-stuffit",
  1956.                                "application/x-shockwave-flash",
  1957.                                "application/x-troff-msvideo",
  1958.                                "application/x-zip-compressed",
  1959.                                "application/xml",
  1960.                                "application/zip",
  1961.                                "application/msword",
  1962.                                "application/mspowerpoint",
  1963.                                "application/vnd.ms-excel",
  1964.                                "application/vnd.ms-powerpoint",
  1965.                                "application/vnd.ms-word",
  1966.                                "application/vnd.ms-word.document.macroEnabled.12",
  1967.                                "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  1968.                                "application/vnd.ms-word.template.macroEnabled.12",
  1969.                                "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
  1970.                                "application/vnd.ms-powerpoint.template.macroEnabled.12",
  1971.                                "application/vnd.openxmlformats-officedocument.presentationml.template",
  1972.                                "application/vnd.ms-powerpoint.addin.macroEnabled.12",
  1973.                                "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
  1974.                                "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
  1975.                                "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
  1976.                                "application/vnd.openxmlformats-officedocument.presentationml.presentation",
  1977.                                "application/vnd.ms-excel.addin.macroEnabled.12",
  1978.                                "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
  1979.                                "application/vnd.ms-excel.sheet.macroEnabled.12",
  1980.                                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  1981.                                "application/vnd.ms-excel.template.macroEnabled.12",
  1982.                                "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
  1983.                                "audio/*",
  1984.                                "image/*",
  1985.                                "video/*",
  1986.                                "multipart/x-zip",
  1987.                                "multipart/x-gzip",
  1988.                                "text/richtext",
  1989.                                "text/plain",
  1990.                                "text/xml");
  1991.  
  1992.     }
  1993.  
  1994.     /**
  1995.      * Constructor. Checks if the file has been uploaded
  1996.      *
  1997.      * The constructor takes $_FILES['form_field'] array as argument
  1998.      * where form_field is the form field name
  1999.      *
  2000.      * The constructor will check if the file has been uploaded in its temporary location, and
  2001.      * accordingly will set {@link uploaded} (and {@link error} is an error occurred)
  2002.      *
  2003.      * If the file has been uploaded, the constructor will populate all the variables holding the upload
  2004.      * information (none of the processing class variables are used here).
  2005.      * You can have access to information about the file (name, size, MIME type...).
  2006.      *
  2007.      *
  2008.      * Alternatively, you can set the first argument to be a local filename (string)
  2009.      * This allows processing of a local file, as if the file was uploaded
  2010.      *
  2011.      * The optional second argument allows you to set the language for the error messages
  2012.      *
  2013.      * @access private
  2014.      * @param  array  $file $_FILES['form_field']
  2015.      *     or   string $file Local filename
  2016.      * @param  string $lang Optional language code
  2017.      */
  2018.     function upload($file$lang 'en_GB'{
  2019.  
  2020.         $this->version            = '0.26';
  2021.  
  2022.         $this->file_src_name      = '';
  2023.         $this->file_src_name_body = '';
  2024.         $this->file_src_name_ext  = '';
  2025.         $this->file_src_mime      = '';
  2026.         $this->file_src_size      = '';
  2027.         $this->file_src_error     = '';
  2028.         $this->file_src_pathname  '';
  2029.         $this->file_src_temp      '';
  2030.  
  2031.         $this->file_dst_path      '';
  2032.         $this->file_dst_name      = '';
  2033.         $this->file_dst_name_body = '';
  2034.         $this->file_dst_name_ext  = '';
  2035.         $this->file_dst_pathname  '';
  2036.  
  2037.         $this->image_src_x        null;
  2038.         $this->image_src_y        null;
  2039.         $this->image_src_bits     null;
  2040.         $this->image_src_type     null;
  2041.         $this->image_src_pixels   null;
  2042.         $this->image_dst_x        0;
  2043.         $this->image_dst_y        0;
  2044.  
  2045.         $this->uploaded           = true;
  2046.         $this->no_upload_check    = false;
  2047.         $this->processed          = true;
  2048.         $this->error              = '';
  2049.         $this->log                = '';
  2050.         $this->allowed            = array();
  2051.         $this->forbidden          = array();
  2052.         $this->file_is_image      false;
  2053.         $this->init();
  2054.         $info                     null;
  2055.         $mime_from_browser        null;
  2056.  
  2057.         // sets default language
  2058.         $this->translation        = array();
  2059.         $this->translation['file_error']                  'File error. Please try again.';
  2060.         $this->translation['local_file_missing']          'Local file doesn\'t exist.';
  2061.         $this->translation['local_file_not_readable']     'Local file is not readable.';
  2062.         $this->translation['uploaded_too_big_ini']        'File upload error (the uploaded file exceeds the upload_max_filesize directive in php.ini).';
  2063.         $this->translation['uploaded_too_big_html']       'File upload error (the uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form).';
  2064.         $this->translation['uploaded_partial']            'File upload error (the uploaded file was only partially uploaded).';
  2065.         $this->translation['uploaded_missing']            'File upload error (no file was uploaded).';
  2066.         $this->translation['uploaded_unknown']            'File upload error (unknown error code).';
  2067.         $this->translation['try_again']                   'File upload error. Please try again.';
  2068.         $this->translation['file_too_big']                'File too big.';
  2069.         $this->translation['no_mime']                     'MIME type can\'t be detected.';
  2070.         $this->translation['incorrect_file']              'Incorrect type of file.';
  2071.         $this->translation['image_too_wide']              'Image too wide.';
  2072.         $this->translation['image_too_narrow']            'Image too narrow.';
  2073.         $this->translation['image_too_high']              'Image too high.';
  2074.         $this->translation['image_too_short']             'Image too short.';
  2075.         $this->translation['ratio_too_high']              'Image ratio too high (image too wide).';
  2076.         $this->translation['ratio_too_low']               'Image ratio too low (image too high).';
  2077.         $this->translation['too_many_pixels']             'Image has too many pixels.';
  2078.         $this->translation['not_enough_pixels']           'Image has not enough pixels.';
  2079.         $this->translation['file_not_uploaded']           'File not uploaded. Can\'t carry on a process.';
  2080.         $this->translation['already_exists']              '%s already exists. Please change the file name.';
  2081.         $this->translation['temp_file_missing']           'No correct temp source file. Can\'t carry on a process.';
  2082.         $this->translation['source_missing']              'No correct uploaded source file. Can\'t carry on a process.';
  2083.         $this->translation['destination_dir']             'Destination directory can\'t be created. Can\'t carry on a process.';
  2084.         $this->translation['destination_dir_missing']     'Destination directory doesn\'t exist. Can\'t carry on a process.';
  2085.         $this->translation['destination_path_not_dir']    'Destination path is not a directory. Can\'t carry on a process.';
  2086.         $this->translation['destination_dir_write']       'Destination directory can\'t be made writeable. Can\'t carry on a process.';
  2087.         $this->translation['destination_path_write']      'Destination path is not a writeable. Can\'t carry on a process.';
  2088.         $this->translation['temp_file']                   'Can\'t create the temporary file. Can\'t carry on a process.';
  2089.         $this->translation['source_not_readable']         'Source file is not readable. Can\'t carry on a process.';
  2090.         $this->translation['no_create_support']           'No create from %s support.';
  2091.         $this->translation['create_error']                'Error in creating %s image from source.';
  2092.         $this->translation['source_invalid']              'Can\'t read image source. Not an image?.';
  2093.         $this->translation['gd_missing']                  'GD doesn\'t seem to be present.';
  2094.         $this->translation['watermark_no_create_support''No create from %s support, can\'t read watermark.';
  2095.         $this->translation['watermark_create_error']      'No %s read support, can\'t create watermark.';
  2096.         $this->translation['watermark_invalid']           'Unknown image format, can\'t read watermark.';
  2097.         $this->translation['file_create']                 'No %s create support.';
  2098.         $this->translation['no_conversion_type']          'No conversion type defined.';
  2099.         $this->translation['copy_failed']                 'Error copying file on the server. copy() failed.';
  2100.         $this->translation['reading_failed']              'Error reading the file.';
  2101.  
  2102.         // determines the language
  2103.         $this->lang               $lang;
  2104.         if ($this->lang != 'en_GB' && file_exists('lang/class.upload.' $lang '.php')) {
  2105.             $translation null;
  2106.             include('lang/class.upload.' $lang '.php');
  2107.             if (is_array($translation)) {
  2108.                 $this->translation = array_merge($this->translation$translation);
  2109.             else {
  2110.                 $this->lang 'en_GB';
  2111.             }
  2112.         }
  2113.  
  2114.  
  2115.         // determines the supported MIME types, and matching image format
  2116.         $this->image_supported array();
  2117.         if ($this->gdversion()) {
  2118.             if (imagetypes(IMG_GIF{
  2119.                 $this->image_supported['image/gif''gif';
  2120.             }
  2121.             if (imagetypes(IMG_JPG{
  2122.                 $this->image_supported['image/jpg''jpg';
  2123.                 $this->image_supported['image/jpeg''jpg';
  2124.                 $this->image_supported['image/pjpeg''jpg';
  2125.             }
  2126.             if (imagetypes(IMG_PNG{
  2127.                 $this->image_supported['image/png''png';
  2128.                 $this->image_supported['image/x-png''png';
  2129.             }
  2130.             if (imagetypes(IMG_WBMP{
  2131.                 $this->image_supported['image/bmp''bmp';
  2132.                 $this->image_supported['image/x-ms-bmp''bmp';
  2133.                 $this->image_supported['image/x-windows-bmp''bmp';
  2134.             }
  2135.         }
  2136.  
  2137.         // display some system information
  2138.         if (empty($this->log)) {
  2139.             $this->log .= '<b>system information</b><br />';
  2140.             $inis ini_get_all();
  2141.             $open_basedir (array_key_exists('open_basedir'$inis&& array_key_exists('local_value'$inis['open_basedir']&& !empty($inis['open_basedir']['local_value'])) $inis['open_basedir']['local_value'false;
  2142.             $gd           $this->gdversion($this->gdversion(true'GD not present';
  2143.             $supported    trim((in_array('png'$this->image_supported'png' ''' ' (in_array('jpg'$this->image_supported'jpg' ''' ' (in_array('gif'$this->image_supported'gif' ''' ' (in_array('bmp'$this->image_supported'bmp' ''));
  2144.             $this->log .= '-&nbsp;class version           : ' $this->version . '<br />';
  2145.             $this->log .= '-&nbsp;GD version              : ' $gd '<br />';
  2146.             $this->log .= '-&nbsp;supported image types   : ' (!empty($supported$supported 'none''<br />';
  2147.             $this->log .= '-&nbsp;open_basedir            : ' (!empty($open_basedir$open_basedir 'no restriction''<br />';
  2148.             $this->log .= '-&nbsp;language                : ' $this->lang '<br />';
  2149.         }
  2150.  
  2151.         if (!$file{
  2152.             $this->uploaded = false;
  2153.             $this->error = $this->translate('file_error');
  2154.         }
  2155.  
  2156.         // check if we sent a local filename rather than a $_FILE element
  2157.         if (!is_array($file)) {
  2158.             if (empty($file)) {
  2159.                 $this->uploaded = false;
  2160.                 $this->error = $this->translate('file_error');
  2161.             else {
  2162.                 $this->no_upload_check = TRUE;
  2163.                 // this is a local filename, i.e.not uploaded
  2164.                 $this->log .= '<b>' $this->translate("source is a local file"' ' $file '</b><br />';
  2165.  
  2166.                 if ($this->uploaded && !file_exists($file)) {
  2167.                     $this->uploaded = false;
  2168.                     $this->error = $this->translate('local_file_missing');
  2169.                 }
  2170.  
  2171.                 if ($this->uploaded && !is_readable($file)) {
  2172.                     $this->uploaded = false;
  2173.                     $this->error = $this->translate('local_file_not_readable');
  2174.                 }
  2175.  
  2176.                 if ($this->uploaded{
  2177.                     $this->file_src_pathname   $file;
  2178.                     $this->file_src_name       = basename($file);
  2179.                     $this->log .= '- local file name OK<br />';
  2180.                     ereg('\.([^\.]*$)'$this->file_src_name$extension);
  2181.                     if (is_array($extension)) {
  2182.                         $this->file_src_name_ext      = strtolower($extension[1]);
  2183.                         $this->file_src_name_body     = substr($this->file_src_name0((strlen($this->file_src_namestrlen($this->file_src_name_ext)))-1);
  2184.                     else {
  2185.                         $this->file_src_name_ext      = '';
  2186.                         $this->file_src_name_body     = $this->file_src_name;
  2187.                     }
  2188.                     $this->file_src_size = (file_exists($filefilesize($file0);
  2189.                 }
  2190.                 $this->file_src_error = 0;
  2191.             }
  2192.         else {
  2193.             // this is an element from $_FILE, i.e. an uploaded file
  2194.             $this->log .= '<b>source is an uploaded file</b><br />';
  2195.             if ($this->uploaded{
  2196.                 $this->file_src_error         = $file['error'];
  2197.                 switch($this->file_src_error{
  2198.                     case 0:
  2199.                         // all is OK
  2200.                         $this->log .= '- upload OK<br />';
  2201.                         break;
  2202.                     case 1:
  2203.                         $this->uploaded = false;
  2204.                         $this->error = $this->translate('uploaded_too_big_ini');
  2205.                         break;
  2206.                     case 2:
  2207.                         $this->uploaded = false;
  2208.                         $this->error = $this->translate('uploaded_too_big_html');
  2209.                         break;
  2210.                     case 3:
  2211.                         $this->uploaded = false;
  2212.                         $this->error = $this->translate('uploaded_partial');
  2213.                         break;
  2214.                     case 4:
  2215.                         $this->uploaded = false;
  2216.                         $this->error = $this->translate('uploaded_missing');
  2217.                         break;
  2218.                     default:
  2219.                         $this->uploaded = false;
  2220.                         $this->error = $this->translate('uploaded_unknown'' ('.$this->file_src_error.')';
  2221.                 }
  2222.             }
  2223.  
  2224.             if ($this->uploaded{
  2225.                 $this->file_src_pathname   $file['tmp_name'];
  2226.                 $this->file_src_name       = $file['name'];
  2227.                 if ($this->file_src_name == ''{
  2228.                     $this->uploaded = false;
  2229.                     $this->error = $this->translate('try_again');
  2230.                 }
  2231.             }
  2232.  
  2233.             if ($this->uploaded{
  2234.                 $this->log .= '- file name OK<br />';
  2235.                 ereg('\.([^\.]*$)'$this->file_src_name$extension);
  2236.                 if (is_array($extension)) {
  2237.                     $this->file_src_name_ext      = strtolower($extension[1]);
  2238.                     $this->file_src_name_body     = substr($this->file_src_name0((strlen($this->file_src_namestrlen($this->file_src_name_ext)))-1);
  2239.                 else {
  2240.                     $this->file_src_name_ext      = '';
  2241.                     $this->file_src_name_body     = $this->file_src_name;
  2242.                 }
  2243.                 $this->file_src_size = $file['size'];
  2244.                 $mime_from_browser $file['type'];
  2245.             }
  2246.         }
  2247.  
  2248.         if ($this->uploaded{
  2249.             $this->file_src_mime = null;
  2250.             // checks MIME type with Fileinfo PECL extension
  2251.             if (!$this->file_src_mime || !is_string($this->file_src_mime|| empty($this->file_src_mime)) {
  2252.                 if (getenv('MAGIC'=== FALSE{
  2253.                     if (substr(PHP_OS03== 'WIN'{
  2254.                         putenv('MAGIC=' realpath(ini_get('extension_dir''/../''extras/magic');
  2255.                     else {
  2256.                         putenv('MAGIC=/usr/share/file/magic');
  2257.                     }
  2258.                 }
  2259.                 if (function_exists('finfo_open')) {
  2260.                     $f @finfo_open(FILEINFO_MIMEgetenv('MAGIC'));
  2261.                     if (is_resource($f)) {
  2262.                         $mime finfo_file($frealpath($this->file_src_pathname));
  2263.                         finfo_close($f);
  2264.                         $this->file_src_mime = $mime;
  2265.                         $this->log .= '- MIME type detected as ' $this->file_src_mime . ' by Fileinfo PECL extension<br />';
  2266.                     }
  2267.                 elseif (class_exists('finfo')) {
  2268.                     $f new finfoFILEINFO_MIME );
  2269.                     $this->file_src_mime = $info->file(realpath($this->file_src_pathname));
  2270.                     $this->log .= '- MIME type detected as ' $this->file_src_mime . ' by Fileinfo PECL extension<br />';
  2271.                 }
  2272.             }
  2273.             // checks MIME type with shell if unix access is authorized
  2274.             if (!$this->file_src_mime || !is_string($this->file_src_mime|| empty($this->file_src_mime)) {
  2275.                 if (substr(PHP_OS03!= 'WIN' && strlen($mime @shell_exec("file -bi ".escapeshellarg($this->file_src_pathname))) != 0{
  2276.                     $this->file_src_mime = trim($mime);
  2277.                     $this->log .= '- MIME type detected as ' $this->file_src_mime . ' by UNIX file() command<br />';
  2278.                 }
  2279.             }
  2280.             // checks MIME type with mime_magic
  2281.             if (!$this->file_src_mime || !is_string($this->file_src_mime|| empty($this->file_src_mime)) {
  2282.                 if (function_exists('mime_content_type')) {
  2283.                     $this->file_src_mime = mime_content_type($this->file_src_pathname);
  2284.                     $this->log .= '- MIME type detected as ' $this->file_src_mime . ' by mime_content_type()<br />';
  2285.                 }
  2286.             }
  2287.             // checks MIME type with getimagesize()
  2288.             if (!$this->file_src_mime || !is_string($this->file_src_mime|| empty($this->file_src_mime)) {
  2289.                 $info getimagesize($this->file_src_pathname);
  2290.                 if (is_array($info&& array_key_exists('mime'$info)) {
  2291.                     $this->file_src_mime = trim($info['mime']);
  2292.                     if (empty($this->file_src_mime)) {
  2293.                         $mime (is_array($info&& array_key_exists(2$info$info[2null)// 1 = GIF, 2 = JPG, 3 = PNG
  2294.                         $this->file_src_mime = ($mime==IMAGETYPE_GIF 'image/gif' ($mime==IMAGETYPE_JPEG 'image/jpeg' ($mime==IMAGETYPE_PNG 'image/png' ($mime==IMAGETYPE_BMP 'image/bmp' null))));
  2295.                     }
  2296.                     $this->log .= '- MIME type detected as ' $this->file_src_mime . ' by PHP getimagesize() function<br />';
  2297.                 }
  2298.             }
  2299.  
  2300.             // default to MIME from browser (or Flash)
  2301.             if (!empty($mime_from_browser&& !$this->file_src_mime || !is_string($this->file_src_mime|| empty($this->file_src_mime)) {
  2302.                 $this->file_src_mime =$mime_from_browser;
  2303.                 $this->log .= '- MIME type detected as ' $this->file_src_mime . ' by browser<br />';
  2304.             }
  2305.  
  2306.             // we need to work some magic if we upload via Flash
  2307.             if ($this->file_src_mime == 'application/octet-stream' || !$this->file_src_mime || !is_string($this->file_src_mime|| empty($this->file_src_mime)) {
  2308.                 if ($this->file_src_mime == 'application/octet-stream'$this->log .= '- Flash may be rewriting MIME as application/octet-stream<br />';
  2309.                 $this->log .= ' - Try to guess MIME type from file extension (' $this->file_src_name_ext . '): ';
  2310.                 switch($this->file_src_name_ext{
  2311.                     case 'jpg':
  2312.                     case 'jpeg':
  2313.                     case 'jpe':
  2314.                         $this->file_src_mime = 'image/jpeg';
  2315.                         break;
  2316.                     case 'gif':
  2317.                         $this->file_src_mime = 'image/gif';
  2318.                         break;
  2319.                     case 'png':
  2320.                         $this->file_src_mime = 'image/png';
  2321.                         break;
  2322.                     case 'bmp':
  2323.                         $this->file_src_mime = 'image/bmp';
  2324.                         break;
  2325.                     case 'js' :
  2326.                         $this->file_src_mime = 'application/x-javascript';
  2327.                         break;
  2328.                     case 'json' :
  2329.                         $this->file_src_mime = 'application/json';
  2330.                         break;
  2331.                     case 'tiff' :
  2332.                         $this->file_src_mime = 'image/tiff';
  2333.                         break;
  2334.                     case 'css' :
  2335.                         $this->file_src_mime = 'text/css';
  2336.                         break;
  2337.                     case 'xml' :
  2338.                         $this->file_src_mime = 'application/xml';
  2339.                         break;
  2340.                     case 'doc' :
  2341.                     case 'docx' :
  2342.                         $this->file_src_mime = 'application/msword';
  2343.                         break;
  2344.                     case 'xls' :
  2345.                     case 'xlt' :
  2346.                     case 'xlm' :
  2347.                     case 'xld' :
  2348.                     case 'xla' :
  2349.                     case 'xlc' :
  2350.                     case 'xlw' :
  2351.                     case 'xll' :
  2352.                         $this->file_src_mime = 'application/vnd.ms-excel';
  2353.                         break;
  2354.                     case 'ppt' :
  2355.                     case 'pps' :
  2356.                         $this->file_src_mime = 'application/vnd.ms-powerpoint';
  2357.                         break;
  2358.                     case 'rtf' :
  2359.                         $this->file_src_mime = 'application/rtf';
  2360.                         break;
  2361.                     case 'pdf' :
  2362.                         $this->file_src_mime = 'application/pdf';
  2363.                         break;
  2364.                     case 'html' :
  2365.                     case 'htm' :
  2366.                     case 'php' :
  2367.                         $this->file_src_mime = 'text/html';
  2368.                         break;
  2369.                     case 'txt' :
  2370.                         $this->file_src_mime = 'text/plain';
  2371.                         break;
  2372.                     case 'mpeg' :
  2373.                     case 'mpg' :
  2374.                     case 'mpe' :
  2375.                         $this->file_src_mime = 'video/mpeg';
  2376.                         break;
  2377.                     case 'mp3' :
  2378.                         $this->file_src_mime = 'audio/mpeg3';
  2379.                         break;
  2380.                     case 'wav' :
  2381.                         $this->file_src_mime = 'audio/wav';
  2382.                         break;
  2383.                     case 'aiff' :
  2384.                     case 'aif' :
  2385.                         $this->file_src_mime = 'audio/aiff';
  2386.                         break;
  2387.                     case 'avi' :
  2388.                         $this->file_src_mime = 'video/msvideo';
  2389.                         break;
  2390.                     case 'wmv' :
  2391.                         $this->file_src_mime = 'video/x-ms-wmv';
  2392.                         break;
  2393.                     case 'mov' :
  2394.                         $this->file_src_mime = 'video/quicktime';
  2395.                         break;
  2396.                     case 'zip' :
  2397.                         $this->file_src_mime = 'application/zip';
  2398.                         break;
  2399.                     case 'tar' :
  2400.                         $this->file_src_mime = 'application/x-tar';
  2401.                         break;
  2402.                     case 'swf' :
  2403.                         $this->file_src_mime = 'application/x-shockwave-flash';
  2404.                         break;
  2405.                 }
  2406.                 if ($this->file_src_mime == 'application/octet-stream'{
  2407.                     $this->log .= 'doesn\t look like anything known<br />';
  2408.                 else {
  2409.                     $this->log .= 'MIME type set to ' $this->file_src_mime . '<br />';
  2410.                 }
  2411.             }
  2412.  
  2413.             if (!$this->file_src_mime || !is_string($this->file_src_mime|| empty($this->file_src_mime)) {
  2414.                 $this->log .= '- MIME type couldn\'t be detected!<br />';
  2415.             }
  2416.  
  2417.             // determine whether the file is an image
  2418.             if ($this->file_src_mime && is_string($this->file_src_mime&& !empty($this->file_src_mime&& array_key_exists($this->file_src_mime$this->image_supported)) {
  2419.                 $this->file_is_image true;
  2420.                 $this->image_src_type $this->image_supported[$this->file_src_mime];
  2421.             }
  2422.  
  2423.             // if the file is an image, we gather some useful data
  2424.             if ($this->file_is_image{
  2425.                 $info @getimagesize($this->file_src_pathname);
  2426.                 if (is_array($info)) {
  2427.                     $this->image_src_x    $info[0];
  2428.                     $this->image_src_y    $info[1];
  2429.                     $this->image_src_pixels $this->image_src_x $this->image_src_y;
  2430.                     $this->image_src_bits array_key_exists('bits'$info$info['bits'null;
  2431.                 else {
  2432.                     $this->log .= '- can\'t retrieve image information. open_basedir restriction in place?<br />';
  2433.                 }
  2434.             }
  2435.  
  2436.             $this->log .= '- source variables<br />';
  2437.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_src_name         : ' $this->file_src_name . '<br />';
  2438.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_src_name_body    : ' $this->file_src_name_body . '<br />';
  2439.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_src_name_ext     : ' $this->file_src_name_ext . '<br />';
  2440.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_src_pathname     : ' $this->file_src_pathname '<br />';
  2441.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_src_mime         : ' $this->file_src_mime . '<br />';
  2442.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_src_size         : ' $this->file_src_size . ' (max= ' $this->file_max_size . ')<br />';
  2443.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_src_error        : ' $this->file_src_error . '<br />';
  2444.  
  2445.             if ($this->file_is_image{
  2446.                 $this->log .= '- source file is an image<br />';
  2447.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_src_x           : ' $this->image_src_x '<br />';
  2448.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_src_y           : ' $this->image_src_y '<br />';
  2449.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_src_pixels      : ' $this->image_src_pixels '<br />';
  2450.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_src_type        : ' $this->image_src_type '<br />';
  2451.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_src_bits        : ' $this->image_src_bits '<br />';
  2452.             }
  2453.         }
  2454.  
  2455.     }
  2456.  
  2457.     /**
  2458.      * Returns the version of GD
  2459.      *
  2460.      * @access public
  2461.      * @param  boolean  $full Optional flag to get precise version
  2462.      * @return float GD version
  2463.      */
  2464.     function gdversion($full false{
  2465.         static $gd_version null;
  2466.         static $gd_full_version null;
  2467.         if ($gd_version === null{
  2468.             if (function_exists('gd_info')) {
  2469.                 $gd gd_info();
  2470.                 $gd $gd["GD Version"];
  2471.                 $regex "/([\d\.]+)/i";
  2472.             else {
  2473.                 ob_start();
  2474.                 phpinfo(8);
  2475.                 $gd ob_get_contents();
  2476.                 ob_end_clean();
  2477.                 $regex "/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i";
  2478.             }
  2479.             if (preg_match($regex$gd$m)) {
  2480.                 $gd_full_version = (string) $m[1];
  2481.                 $gd_version = (float) $m[1];
  2482.             else {
  2483.                 $gd_full_version 'none';
  2484.                 $gd_version 0;
  2485.             }
  2486.         }
  2487.         if ($full{
  2488.             return $gd_full_version;
  2489.         else {
  2490.             return $gd_version;
  2491.         }
  2492.     }
  2493.  
  2494.  
  2495.     /**
  2496.      * Creates directories recursively
  2497.      *
  2498.      * @access private
  2499.      * @param  string  $path Path to create
  2500.      * @param  integer $mode Optional permissions
  2501.      * @return boolean Success
  2502.      */
  2503.     function rmkdir($path$mode 0777{
  2504.         return is_dir($path|| $this->rmkdir(dirname($path)$mode&& $this->_mkdir($path$mode) );
  2505.     }
  2506.  
  2507.  
  2508.     /**
  2509.      * Creates directory
  2510.      *
  2511.      * @access private
  2512.      * @param  string  $path Path to create
  2513.      * @param  integer $mode Optional permissions
  2514.      * @return boolean Success
  2515.      */
  2516.     function _mkdir($path$mode 0777{
  2517.         $old umask(0);
  2518.         $res @mkdir($path$mode);
  2519.         umask($old);
  2520.         return $res;
  2521.     }
  2522.  
  2523.  
  2524.     /**
  2525.      * Translate error messages
  2526.      *
  2527.      * @access private
  2528.      * @param  string  $str    Message to translate
  2529.      * @param  array   $tokens Optional token values
  2530.      * @return string Translated string
  2531.      */
  2532.     function translate($str$tokens array()) {
  2533.         if (array_key_exists($str$this->translation)) $str $this->translation[$str];
  2534.         if (is_array($tokens&& sizeof($tokens0)   $str vsprintf($str$tokens);
  2535.         return $str;
  2536.     }
  2537.  
  2538.     /**
  2539.      * Decodes colors
  2540.      *
  2541.      * @access private
  2542.      * @param  string  $color  Color string
  2543.      * @return array RGB colors
  2544.      */
  2545.     function getcolors($color{
  2546.         $r sscanf($color"#%2x%2x%2x");
  2547.         $red   (array_key_exists(0$r&& is_numeric($r[0]$r[00);
  2548.         $green (array_key_exists(1$r&& is_numeric($r[1]$r[10);
  2549.         $blue  (array_key_exists(2$r&& is_numeric($r[2]$r[20);
  2550.         return array($red$green$blue);
  2551.     }
  2552.  
  2553.     /**
  2554.      * Creates a container image
  2555.      *
  2556.      * @access private
  2557.      * @param  integer  $x    Width
  2558.      * @param  integer  $y    Height
  2559.      * @param  boolean  $fill Optional flag to draw the background color or not
  2560.      * @param  boolean  $trsp Optional flag to set the background to be transparent
  2561.      * @return resource Container image
  2562.      */
  2563.     function imagecreatenew($x$y$fill true$trsp false{
  2564.         if ($x 1$x 1if ($y 1$y 1;
  2565.         if ($this->gdversion(>= && !$this->image_is_palette{
  2566.             // create a true color image
  2567.             $dst_im imagecreatetruecolor($x$y);
  2568.             // this preserves transparency in PNGs, in true color
  2569.             if (empty($this->image_background_color|| $trsp{
  2570.                 imagealphablending($dst_imfalse );
  2571.                 imagefilledrectangle($dst_im00$x$yimagecolorallocatealpha($dst_im000127));
  2572.             }
  2573.         else {
  2574.             // creates a palette image
  2575.             $dst_im imagecreate($x$y);
  2576.             // preserves transparency for palette images, if the original image has transparency
  2577.             if (($fill && $this->image_is_transparent && empty($this->image_background_color)) || $trsp{
  2578.                 imagefilledrectangle($dst_im00$x$y$this->image_transparent_color);
  2579.                 imagecolortransparent($dst_im$this->image_transparent_color);
  2580.             }
  2581.         }
  2582.         // fills with background color if any is set
  2583.         if ($fill && !empty($this->image_background_color&& !$trsp{
  2584.             list($red$green$blue$this->getcolors($this->image_background_color);
  2585.             $background_color imagecolorallocate($dst_im$red$green$blue);
  2586.             imagefilledrectangle($dst_im00$x$y$background_color);
  2587.         }
  2588.         return $dst_im;
  2589.     }
  2590.  
  2591.  
  2592.     /**
  2593.      * Transfers an image from the container to the destination image
  2594.      *
  2595.      * @access private
  2596.      * @param  resource $src_im Container image
  2597.      * @param  resource $dst_im Destination image
  2598.      * @return resource Destination image
  2599.      */
  2600.     function imagetransfer($src_im$dst_im{
  2601.         if (is_resource($dst_im)) imagedestroy($dst_im);
  2602.         $dst_im $src_im;
  2603.         return $dst_im;
  2604.     }
  2605.  
  2606.     /**
  2607.      * Merges two images
  2608.      *
  2609.      * If the output format is PNG, then we do it pixel per pixel to retain the alpha channel
  2610.      *
  2611.      * @access private
  2612.      * @param  resource $dst_img Destination image
  2613.      * @param  resource $src_img Overlay image
  2614.      * @param  int      $dst_x   x-coordinate of destination point
  2615.      * @param  int      $dst_y   y-coordinate of destination point
  2616.      * @param  int      $src_x   x-coordinate of source point
  2617.      * @param  int      $src_y   y-coordinate of source point
  2618.      * @param  int      $src_w   Source width
  2619.      * @param  int      $src_h   Source height
  2620.      * @param  int      $pct     Optional percentage of the overlay, between 0 and 100 (default: 100)
  2621.      * @return resource Destination image
  2622.      */
  2623.     function imagecopymergealpha(&$dst_im&$src_im$dst_x$dst_y$src_x$src_y$src_w$src_h$pct 0{
  2624.         $dst_x = (int) $dst_x;
  2625.         $dst_y = (int) $dst_y;
  2626.         $src_x = (int) $src_x;
  2627.         $src_y = (int) $src_y;
  2628.         $src_w = (int) $src_w;
  2629.         $src_h = (int) $src_h;
  2630.         $pct   = (int) $pct;
  2631.         $dst_w imagesx($dst_im);
  2632.         $dst_h imagesy($dst_im);
  2633.  
  2634.         for ($y $src_y$y $src_h$y++{
  2635.             for ($x $src_x$x $src_w$x++{
  2636.  
  2637.                 if ($x $dst_x >= && $x $dst_x $dst_w && $x $src_x >= && $x $src_x $src_w
  2638.                  && $y $dst_y >= && $y $dst_y $dst_h && $y $src_y >= && $y $src_y $src_h{
  2639.  
  2640.                     $dst_pixel imagecolorsforindex($dst_imimagecolorat($dst_im$x $dst_x$y $dst_y));
  2641.                     $src_pixel imagecolorsforindex($src_imimagecolorat($src_im$x $src_x$y $src_y));
  2642.  
  2643.                     $src_alpha ($src_pixel['alpha'127);
  2644.                     $dst_alpha ($dst_pixel['alpha'127);
  2645.                     $opacity $src_alpha $pct 100;
  2646.                     if ($dst_alpha >= $opacity$alpha $dst_alpha;
  2647.                     if ($dst_alpha $opacity)  $alpha $opacity;
  2648.                     if ($alpha 1$alpha 1;
  2649.  
  2650.                     if ($opacity 0{
  2651.                         $dst_red   round(( ($dst_pixel['red']   $dst_alpha ($opacity)) ) );
  2652.                         $dst_green round(( ($dst_pixel['green'$dst_alpha ($opacity)) ) );
  2653.                         $dst_blue  round(( ($dst_pixel['blue']  $dst_alpha ($opacity)) ) );
  2654.                         $src_red   round((($src_pixel['red']   $opacity)) );
  2655.                         $src_green round((($src_pixel['green'$opacity)) );
  2656.                         $src_blue  round((($src_pixel['blue']  $opacity)) );
  2657.                         $red   round(($dst_red   $src_red  ($dst_alpha ($opacity$opacity));
  2658.                         $green round(($dst_green $src_green($dst_alpha ($opacity$opacity));
  2659.                         $blue  round(($dst_blue  $src_blue ($dst_alpha ($opacity$opacity));
  2660.                         if ($red   255$red   255;
  2661.                         if ($green 255$green 255;
  2662.                         if ($blue  255$blue  255;
  2663.                         $alpha =  round(($alpha127);
  2664.                         $color imagecolorallocatealpha($dst_im$red$green$blue$alpha);
  2665.                         imagesetpixel($dst_im$x $dst_x$y $dst_y$color);
  2666.                     }
  2667.                 }
  2668.             }
  2669.         }
  2670.         return true;
  2671.     }
  2672.  
  2673.  
  2674.  
  2675.     /**
  2676.      * Actually uploads the file, and act on it according to the set processing class variables
  2677.      *
  2678.      * This function copies the uploaded file to the given location, eventually performing actions on it.
  2679.      * Typically, you can call {@link process} several times for the same file,
  2680.      * for instance to create a resized image and a thumbnail of the same file.
  2681.      * The original uploaded file remains intact in its temporary location, so you can use {@link process} several times.
  2682.      * You will be able to delete the uploaded file with {@link clean} when you have finished all your {@link process} calls.
  2683.      *
  2684.      * According to the processing class variables set in the calling file, the file can be renamed,
  2685.      * and if it is an image, can be resized or converted.
  2686.      *
  2687.      * When the processing is completed, and the file copied to its new location, the
  2688.      * processing class variables will be reset to their default value.
  2689.      * This allows you to set new properties, and perform another {@link process} on the same uploaded file
  2690.      *
  2691.      * If the function is called with a null or empty argument, then it will return the content of the picture
  2692.      *
  2693.      * It will set {@link processed} (and {@link error} is an error occurred)
  2694.      *
  2695.      * @access public
  2696.      * @param  string $server_path Optional path location of the uploaded file, with an ending slash
  2697.      * @return string Optional content of the image
  2698.      */
  2699.     function process($server_path null{
  2700.  
  2701.         $this->error        '';
  2702.         $this->processed    true;
  2703.         $return_mode        false;
  2704.         $return_content     null;
  2705.  
  2706.         if (empty($server_path|| is_null($server_path)) {
  2707.             $this->log .= '<b>process file and return the content</b><br />';
  2708.             $return_mode true;
  2709.         else {
  2710.             if(strtolower(substr(PHP_OS03)) === 'win'{
  2711.                 if (substr($server_path-11!= '\\'$server_path $server_path '\\';
  2712.             else {
  2713.                 if (substr($server_path-11!= '/'$server_path $server_path '/';
  2714.             }
  2715.             $this->log .= '<b>process file to '  $server_path '</b><br />';
  2716.         }
  2717.  
  2718.         // checks file size and mine type
  2719.         if ($this->uploaded{
  2720.  
  2721.             if ($this->file_src_size $this->file_max_size {
  2722.                 $this->processed false;
  2723.                 $this->error $this->translate('file_too_big');
  2724.             else {
  2725.                 $this->log .= '- file size OK<br />';
  2726.             }
  2727.  
  2728.             // turn dangerous scripts into text files
  2729.             if ($this->no_script{
  2730.                 if (((substr($this->file_src_mime05== 'text/' || strpos($this->file_src_mime'javascript'!== false)  && (substr($this->file_src_name-4!= '.txt'))
  2731.                     || preg_match('/\.(php|pl|py|cgi|asp)$/i'$this->file_src_name|| empty($this->file_src_name_ext)) {
  2732.                     $this->file_src_mime 'text/plain';
  2733.                     $this->log .= '- script '  $this->file_src_name ' renamed as ' $this->file_src_name '.txt!<br />';
  2734.                     $this->file_src_name_ext .= (empty($this->file_src_name_ext'txt' '.txt');
  2735.                 }
  2736.             }
  2737.  
  2738.             if ($this->mime_check && empty($this->file_src_mime)) {
  2739.                 $this->processed false;
  2740.                 $this->error $this->translate('no_mime');
  2741.             else if ($this->mime_check && !empty($this->file_src_mime&& strpos($this->file_src_mime'/'!== false{
  2742.                 list($m1$m2explode('/'$this->file_src_mime);
  2743.                 $allowed false;
  2744.                 // check wether the mime type is allowed
  2745.                 foreach($this->allowed as $k => $v{
  2746.                     list($v1$v2explode('/'$v);
  2747.                     if (($v1 == '*' && $v2 == '*'|| ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) {
  2748.                         $allowed true;
  2749.                         break;
  2750.                     }
  2751.                 }
  2752.                 // check wether the mime type is forbidden
  2753.                 foreach($this->forbidden as $k => $v{
  2754.                     list($v1$v2explode('/'$v);
  2755.                     if (($v1 == '*' && $v2 == '*'|| ($v1 == $m1 && ($v2 == $m2 || $v2 == '*'))) {
  2756.                         $allowed false;
  2757.                         break;
  2758.                     }
  2759.                 }
  2760.                 if (!$allowed{
  2761.                     $this->processed false;
  2762.                     $this->error $this->translate('incorrect_file');
  2763.                 else {
  2764.                     $this->log .= '- file mime OK : ' $this->file_src_mime '<br />';
  2765.                 }
  2766.             else {
  2767.                 $this->log .= '- file mime OK : ' $this->file_src_mime '<br />';
  2768.             }
  2769.  
  2770.             // if the file is an image, we can check on its dimensions
  2771.             // these checks are not available if open_basedir restrictions are in place
  2772.             if ($this->file_is_image{
  2773.                 if (is_numeric($this->image_src_x&& is_numeric($this->image_src_y)) {
  2774.                     $ratio $this->image_src_x $this->image_src_y;
  2775.                     if (!is_null($this->image_max_width&& $this->image_src_x $this->image_max_width{
  2776.                         $this->processed false;
  2777.                         $this->error $this->translate('image_too_wide');
  2778.                     }
  2779.                     if (!is_null($this->image_min_width&& $this->image_src_x $this->image_min_width{
  2780.                         $this->processed false;
  2781.                         $this->error $this->translate('image_too_narrow');
  2782.                     }
  2783.                     if (!is_null($this->image_max_height&& $this->image_src_y $this->image_max_height{
  2784.                         $this->processed false;
  2785.                         $this->error $this->translate('image_too_high');
  2786.                     }
  2787.                     if (!is_null($this->image_min_height&& $this->image_src_y $this->image_min_height{
  2788.                         $this->processed false;
  2789.                         $this->error $this->translate('image_too_short');
  2790.                     }
  2791.                     if (!is_null($this->image_max_ratio&& $ratio $this->image_max_ratio{
  2792.                         $this->processed false;
  2793.                         $this->error $this->translate('ratio_too_high');
  2794.                     }
  2795.                     if (!is_null($this->image_min_ratio&& $ratio $this->image_min_ratio{
  2796.                         $this->processed false;
  2797.                         $this->error $this->translate('ratio_too_low');
  2798.                     }
  2799.                     if (!is_null($this->image_max_pixels&& $this->image_src_pixels $this->image_max_pixels{
  2800.                         $this->processed false;
  2801.                         $this->error $this->translate('too_many_pixels');
  2802.                     }
  2803.                     if (!is_null($this->image_min_pixels&& $this->image_src_pixels $this->image_min_pixels{
  2804.                         $this->processed false;
  2805.                         $this->error $this->translate('not_enough_pixels');
  2806.                     }
  2807.                 else {
  2808.                     $this->log .= '- no image properties available, can\'t enforce dimension checks : ' $this->file_src_mime '<br />';
  2809.                 }
  2810.             }
  2811.  
  2812.  
  2813.         else {
  2814.             $this->error $this->translate('file_not_uploaded');
  2815.             $this->processed false;
  2816.         }
  2817.  
  2818.         if ($this->processed{
  2819.             $this->file_dst_path        $server_path;
  2820.  
  2821.             // repopulate dst variables from src
  2822.             $this->file_dst_name        $this->file_src_name;
  2823.             $this->file_dst_name_body   $this->file_src_name_body;
  2824.             $this->file_dst_name_ext    $this->file_src_name_ext;
  2825.  
  2826.             if ($this->image_convert != ''// if we convert as an image
  2827.                 $this->file_dst_name_ext  $this->image_convert;
  2828.                 $this->log .= '- new file name ext : ' $this->image_convert '<br />';
  2829.             }
  2830.             if ($this->file_new_name_body != ''// rename file body
  2831.                 $this->file_dst_name_body $this->file_new_name_body;
  2832.                 $this->log .= '- new file name body : ' $this->file_new_name_body '<br />';
  2833.             }
  2834.             if ($this->file_new_name_ext != ''// rename file ext
  2835.                 $this->file_dst_name_ext  $this->file_new_name_ext;
  2836.                 $this->log .= '- new file name ext : ' $this->file_new_name_ext '<br />';
  2837.             }
  2838.             if ($this->file_name_body_add != ''// append a bit to the name
  2839.                 $this->file_dst_name_body  $this->file_dst_name_body $this->file_name_body_add;
  2840.                 $this->log .= '- file name body add : ' $this->file_name_body_add '<br />';
  2841.             }
  2842.             if ($this->file_safe_name// formats the name
  2843.                 $this->file_dst_name_body str_replace(array(' ''-')array('_','_')$this->file_dst_name_body;
  2844.                 $this->file_dst_name_body ereg_replace('[^A-Za-z0-9_]'''$this->file_dst_name_body;
  2845.                 $this->log .= '- file name safe format<br />';
  2846.             }
  2847.  
  2848.             $this->log .= '- destination variables<br />';
  2849.             if (empty($this->file_dst_path|| is_null($this->file_dst_path)) {
  2850.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_path         : n/a<br />';
  2851.             else {
  2852.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_path         : ' $this->file_dst_path '<br />';
  2853.             }
  2854.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_name_body    : ' $this->file_dst_name_body '<br />';
  2855.             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_name_ext     : ' $this->file_dst_name_ext '<br />';
  2856.  
  2857.             // do we do some image manipulation?
  2858.             $image_manipulation  ($this->file_is_image && (
  2859.                                     $this->image_resize
  2860.                                  || $this->image_convert != ''
  2861.                                  || is_numeric($this->image_brightness)
  2862.                                  || is_numeric($this->image_contrast)
  2863.                                  || is_numeric($this->image_threshold)
  2864.                                  || !empty($this->image_tint_color)
  2865.                                  || !empty($this->image_overlay_color)
  2866.                                  || !empty($this->image_text)
  2867.                                  || $this->image_greyscale
  2868.                                  || $this->image_negative
  2869.                                  || !empty($this->image_watermark)
  2870.                                  || is_numeric($this->image_rotate)
  2871.                                  || is_numeric($this->jpeg_size)
  2872.                                  || !empty($this->image_flip)
  2873.                                  || !empty($this->image_crop)
  2874.                                  || !empty($this->image_border)
  2875.                                  || $this->image_frame 0
  2876.                                  || $this->image_bevel 0
  2877.                                  || $this->image_reflection_height));
  2878.  
  2879.             if ($image_manipulation{
  2880.                 if ($this->image_convert==''{
  2881.                     $this->file_dst_name $this->file_dst_name_body (!empty($this->file_dst_name_ext'.' $this->file_dst_name_ext '');
  2882.                     $this->log .= '- image operation, keep extension<br />';
  2883.                 else {
  2884.                     $this->file_dst_name $this->file_dst_name_body '.' $this->image_convert;
  2885.                     $this->log .= '- image operation, change extension for conversion type<br />';
  2886.                 }
  2887.             else {
  2888.                 $this->file_dst_name $this->file_dst_name_body (!empty($this->file_dst_name_ext'.' $this->file_dst_name_ext '');
  2889.                 $this->log .= '- no image operation, keep extension<br />';
  2890.             }
  2891.  
  2892.             if (!$return_mode{
  2893.                 if (!$this->file_auto_rename{
  2894.                     $this->log .= '- no auto_rename if same filename exists<br />';
  2895.                     $this->file_dst_pathname $this->file_dst_path $this->file_dst_name;
  2896.                 else {
  2897.                     $this->log .= '- checking for auto_rename<br />';
  2898.                     $this->file_dst_pathname $this->file_dst_path $this->file_dst_name;
  2899.                     $body     $this->file_dst_name_body;
  2900.                     $cpt 1;
  2901.                     while (@file_exists($this->file_dst_pathname)) {
  2902.                         $this->file_dst_name_body $body '_' $cpt;
  2903.                         $this->file_dst_name $this->file_dst_name_body (!empty($this->file_dst_name_ext'.' $this->file_dst_name_ext '');
  2904.                         $cpt++;
  2905.                         $this->file_dst_pathname $this->file_dst_path $this->file_dst_name;
  2906.                     }
  2907.                     if ($cpt>1$this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;auto_rename to ' $this->file_dst_name '<br />';
  2908.                 }
  2909.  
  2910.                 $this->log .= '- destination file details<br />';
  2911.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_name         : ' $this->file_dst_name '<br />';
  2912.                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_pathname     : ' $this->file_dst_pathname '<br />';
  2913.  
  2914.                 if ($this->file_overwrite{
  2915.                      $this->log .= '- no overwrite checking<br />';
  2916.                 else {
  2917.                     if (@file_exists($this->file_dst_pathname)) {
  2918.                         $this->processed false;
  2919.                         $this->error $this->translate('already_exists'array($this->file_dst_name));
  2920.                     else {
  2921.                         $this->log .= '- ' $this->file_dst_name ' doesn\'t exist already<br />';
  2922.                     }
  2923.                 }
  2924.             }
  2925.         else {
  2926.             $this->processed false;
  2927.         }
  2928.  
  2929.         // if we have already moved the uploaded file, we use the temporary copy as source file, and check if it exists
  2930.         if (!empty($this->file_src_temp)) {
  2931.             $this->log .= '- use the temp file instead of the original file since it is a second process<br />';
  2932.             $this->file_src_pathname   $this->file_src_temp;
  2933.             if (!file_exists($this->file_src_pathname)) {
  2934.                 $this->processed false;
  2935.                 $this->error $this->translate('temp_file_missing');
  2936.             }
  2937.         // if we haven't a temp file, and that we do check on uploads, we use is_uploaded_file()
  2938.         else if (!$this->no_upload_check{
  2939.             if (!is_uploaded_file($this->file_src_pathname)) {
  2940.                 $this->processed false;
  2941.                 $this->error $this->translate('source_missing');
  2942.             }
  2943.         // otherwise, if we don't check on uploaded files (local file for instance), we use file_exists()
  2944.         else {
  2945.             if (!file_exists($this->file_src_pathname)) {
  2946.                 $this->processed false;
  2947.                 $this->error $this->translate('source_missing');
  2948.             }
  2949.         }
  2950.  
  2951.         // checks if the destination directory exists, and attempt to create it
  2952.         if (!$return_mode{
  2953.             if ($this->processed && !file_exists($this->file_dst_path)) {
  2954.                 if ($this->dir_auto_create{
  2955.                     $this->log .= '- ' $this->file_dst_path ' doesn\'t exist. Attempting creation:';
  2956.                     if (!$this->rmkdir($this->file_dst_path$this->dir_chmod)) {
  2957.                         $this->log .= ' failed<br />';
  2958.                         $this->processed false;
  2959.                         $this->error $this->translate('destination_dir');
  2960.                     else {
  2961.                         $this->log .= ' success<br />';
  2962.                     }
  2963.                 else {
  2964.                     $this->error $this->translate('destination_dir_missing');
  2965.                 }
  2966.             }
  2967.  
  2968.             if ($this->processed && !is_dir($this->file_dst_path)) {
  2969.                 $this->processed false;
  2970.                 $this->error $this->translate('destination_path_not_dir');
  2971.             }
  2972.  
  2973.             // checks if the destination directory is writeable, and attempt to make it writeable
  2974.             $hash md5($this->file_dst_name_body rand(11000));
  2975.             if ($this->processed && !($f @fopen($this->file_dst_path $hash '.' $this->file_dst_name_ext'a+'))) {
  2976.                 if ($this->dir_auto_chmod{
  2977.                     $this->log .= '- ' $this->file_dst_path ' is not writeable. Attempting chmod:';
  2978.                     if (!@chmod($this->file_dst_path$this->dir_chmod)) {
  2979.                         $this->log .= ' failed<br />';
  2980.                         $this->processed false;
  2981.                         $this->error $this->translate('destination_dir_write');
  2982.                     else {
  2983.                         $this->log .= ' success<br />';
  2984.                         if (!($f @fopen($this->file_dst_path $hash '.' $this->file_dst_name_ext'a+'))) // we re-check
  2985.                             $this->processed false;
  2986.                             $this->error $this->translate('destination_dir_write');
  2987.                         else {
  2988.                             @fclose($f);
  2989.                         }
  2990.                     }
  2991.                 else {
  2992.                     $this->processed false;
  2993.                     $this->error $this->translate('destination_path_write');
  2994.                 }
  2995.             else {
  2996.                 if ($this->processed@fclose($f);
  2997.                 @unlink($this->file_dst_path $hash '.' $this->file_dst_name_ext);
  2998.             }
  2999.  
  3000.  
  3001.             // if we have an uploaded file, and if it is the first process, and if we can't access the file directly (open_basedir restriction)
  3002.             // then we create a temp file that will be used as the source file in subsequent processes
  3003.             // the third condition is there to check if the file is not accessible *directly* (it already has positively gone through is_uploaded_file(), so it exists)
  3004.             if (!$this->no_upload_check && empty($this->file_src_temp&& !@file_exists($this->file_src_pathname)) {
  3005.                 $this->log .= '- attempting creating a temp file:';
  3006.                 $hash md5($this->file_dst_name_body rand(11000));
  3007.                 if (move_uploaded_file($this->file_src_pathname$this->file_dst_path $hash '.' $this->file_dst_name_ext)) {
  3008.                     $this->file_src_pathname $this->file_dst_path $hash '.' $this->file_dst_name_ext;
  3009.                     $this->file_src_temp $this->file_src_pathname;
  3010.                     $this->log .= ' file created<br />';
  3011.                     $this->log .= '    temp file is: ' $this->file_src_temp '<br />';
  3012.                 else {
  3013.                     $this->log .= ' failed<br />';
  3014.                     $this->processed false;
  3015.                     $this->error $this->translate('temp_file');
  3016.                 }
  3017.             }
  3018.         }
  3019.  
  3020.         if ($this->processed{
  3021.  
  3022.             // we do a quick check to ensure the file is really an image
  3023.             // we can do this only now, as it would have failed before in case of open_basedir
  3024.             if ($image_manipulation && !@getimagesize($this->file_src_pathname)) {
  3025.                 $this->log .= '- the file is not an image!<br />';
  3026.                 $image_manipulation false;
  3027.             }
  3028.  
  3029.             if ($image_manipulation{
  3030.  
  3031.                 // checks if the source file is readable
  3032.                 if ($this->processed && !($f @fopen($this->file_src_pathname'r'))) {
  3033.                     $this->processed false;
  3034.                     $this->error $this->translate('source_not_readable');
  3035.                 else {
  3036.                     @fclose($f);
  3037.                 }
  3038.  
  3039.                 // we now do all the image manipulations
  3040.                 $this->log .= '- image resizing or conversion wanted<br />';
  3041.                 if ($this->gdversion()) {
  3042.                     switch($this->image_src_type{
  3043.                         case 'jpg':
  3044.                             if (!function_exists('imagecreatefromjpeg')) {
  3045.                                 $this->processed false;
  3046.                                 $this->error $this->translate('no_create_support'array('JPEG'));
  3047.                             else {
  3048.                                 $image_src @imagecreatefromjpeg($this->file_src_pathname);
  3049.                                 if (!$image_src{
  3050.                                     $this->processed false;
  3051.                                     $this->error $this->translate('create_error'array('JPEG'));
  3052.                                 else {
  3053.                                     $this->log .= '- source image is JPEG<br />';
  3054.                                 }
  3055.                             }
  3056.                             break;
  3057.                         case 'png':
  3058.                             if (!function_exists('imagecreatefrompng')) {
  3059.                                 $this->processed false;
  3060.                                 $this->error $this->translate('no_create_support'array('PNG'));
  3061.                             else {
  3062.                                 $image_src @imagecreatefrompng($this->file_src_pathname);
  3063.                                 if (!$image_src{
  3064.                                     $this->processed false;
  3065.                                     $this->error $this->translate('create_error'array('PNG'));
  3066.                                 else {
  3067.                                     $this->log .= '- source image is PNG<br />';
  3068.                                 }
  3069.                             }
  3070.                             break;
  3071.                         case 'gif':
  3072.                             if (!function_exists('imagecreatefromgif')) {
  3073.                                 $this->processed false;
  3074.                                 $this->error $this->translate('no_create_support'array('GIF'));
  3075.                             else {
  3076.                                 $image_src @imagecreatefromgif($this->file_src_pathname);
  3077.                                 if (!$image_src{
  3078.                                     $this->processed false;
  3079.                                     $this->error $this->translate('create_error'array('GIF'));
  3080.                                 else {
  3081.                                     $this->log .= '- source image is GIF<br />';
  3082.                                 }
  3083.                             }
  3084.                             break;
  3085.                         case 'bmp':
  3086.                             if (!method_exists($this'imagecreatefrombmp')) {
  3087.                                 $this->processed false;
  3088.                                 $this->error $this->translate('no_create_support'array('BMP'));
  3089.                             else {
  3090.                                 $image_src @$this->imagecreatefrombmp($this->file_src_pathname);
  3091.                                 if (!$image_src{
  3092.                                     $this->processed false;
  3093.                                     $this->error $this->translate('create_error'array('BMP'));
  3094.                                 else {
  3095.                                     $this->log .= '- source image is BMP<br />';
  3096.                                 }
  3097.                             }
  3098.                             break;
  3099.                         default:
  3100.                             $this->processed false;
  3101.                             $this->error $this->translate('source_invalid');
  3102.                     }
  3103.                 else {
  3104.                     $this->processed false;
  3105.                     $this->error $this->translate('gd_missing');
  3106.                 }
  3107.  
  3108.                 if ($this->processed && $image_src{
  3109.  
  3110.                     // we have to set image_convert if it is not already
  3111.                     if (empty($this->image_convert)) {
  3112.                         $this->log .= '- setting destination file type to ' $this->file_src_name_ext '<br />';
  3113.                         $this->image_convert $this->file_src_name_ext;
  3114.                     }
  3115.  
  3116.                     if (!in_array($this->image_convert$this->image_supported)) {
  3117.                         $this->image_convert 'jpg';
  3118.                     }
  3119.  
  3120.                     // we set the default color to be the background color if we don't output in a transparent format
  3121.                     if ($this->image_convert != 'png' && $this->image_convert != 'gif' && !empty($this->image_default_color&& empty($this->image_background_color)) $this->image_background_color $this->image_default_color;
  3122.                     if (!empty($this->image_background_color)) $this->image_default_color $this->image_background_color;
  3123.                     if (empty($this->image_default_color)) $this->image_default_color '#FFFFFF';
  3124.  
  3125.                     $this->image_src_x imagesx($image_src);
  3126.                     $this->image_src_y imagesy($image_src);
  3127.                     $this->image_dst_x $this->image_src_x;
  3128.                     $this->image_dst_y $this->image_src_y;
  3129.                     $gd_version $this->gdversion();
  3130.                     $ratio_crop null;
  3131.  
  3132.                     if (!imageistruecolor($image_src)) {  // $this->image_src_type == 'gif'
  3133.                         $this->log .= '- image is detected as having a palette<br />';
  3134.                         $this->image_is_palette true;
  3135.                         $this->image_transparent_color imagecolortransparent($image_src);
  3136.                         if ($this->image_transparent_color >= && imagecolorstotal($image_src$this->image_transparent_color{
  3137.                             $this->image_is_transparent true;
  3138.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;palette image is detected as transparent<br />';
  3139.                         }
  3140.                         // if the image has a palette (GIF), we convert it to true color, preserving transparency
  3141.                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;convert palette image to true color<br />';
  3142.                         $true_color imagecreatetruecolor($this->image_src_x$this->image_src_y);
  3143.                         imagealphablending($true_colorfalse);
  3144.                         imagesavealpha($true_colortrue);
  3145.                         for ($x 0$x $this->image_src_x$x++{
  3146.                             for ($y 0$y $this->image_src_y$y++{
  3147.                                 if ($this->image_transparent_color >= && imagecolorat($image_src$x$y== $this->image_transparent_color{
  3148.                                     imagesetpixel($true_color$x$y127 << 24);
  3149.                                 else {
  3150.                                     $rgb imagecolorsforindex($image_srcimagecolorat($image_src$x$y));
  3151.                                     imagesetpixel($true_color$x$y($rgb['alpha'<< 24($rgb['red'<< 16($rgb['green'<< 8$rgb['blue']);
  3152.                                 }
  3153.                             }
  3154.                         }
  3155.                         $image_src $this->imagetransfer($true_color$image_src);
  3156.                         imagealphablending($image_srcfalse);
  3157.                         imagesavealpha($image_srctrue);
  3158.                         $this->image_is_palette false;
  3159.                     }
  3160.  
  3161.  
  3162.                     if ($this->image_resize{
  3163.                         $this->log .= '- resizing...<br />';
  3164.  
  3165.                         if ($this->image_ratio_x{
  3166.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;calculate x size<br />';
  3167.                             $this->image_dst_x round(($this->image_src_x $this->image_y$this->image_src_y);
  3168.                             $this->image_dst_y $this->image_y;
  3169.                         else if ($this->image_ratio_y{
  3170.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;calculate y size<br />';
  3171.                             $this->image_dst_x $this->image_x;
  3172.                             $this->image_dst_y round(($this->image_src_y $this->image_x$this->image_src_x);
  3173.                         else if (is_numeric($this->image_ratio_pixels)) {
  3174.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;calculate x/y size to match a number of pixels<br />';
  3175.                             $pixels $this->image_src_y $this->image_src_x;
  3176.                             $diff sqrt($this->image_ratio_pixels $pixels);
  3177.                             $this->image_dst_x round($this->image_src_x $diff);
  3178.                             $this->image_dst_y round($this->image_src_y $diff);
  3179.                         else if ($this->image_ratio || $this->image_ratio_crop || $this->image_ratio_fill || $this->image_ratio_no_zoom_in || $this->image_ratio_no_zoom_out{
  3180.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;check x/y sizes<br />';
  3181.                             if ((!$this->image_ratio_no_zoom_in && !$this->image_ratio_no_zoom_out)
  3182.                                  || ($this->image_ratio_no_zoom_in && ($this->image_src_x $this->image_x || $this->image_src_y $this->image_y))
  3183.                                  || ($this->image_ratio_no_zoom_out && $this->image_src_x $this->image_x && $this->image_src_y $this->image_y)) {
  3184.                                 $this->image_dst_x $this->image_x;
  3185.                                 $this->image_dst_y $this->image_y;
  3186.                                 if ($this->image_ratio_crop{
  3187.                                     if (!is_string($this->image_ratio_crop)) $this->image_ratio_crop '';
  3188.                                     $this->image_ratio_crop strtolower($this->image_ratio_crop);
  3189.                                     if (($this->image_src_x/$this->image_x($this->image_src_y/$this->image_y)) {
  3190.                                         $this->image_dst_y $this->image_y;
  3191.                                         $this->image_dst_x intval($this->image_src_x*($this->image_y $this->image_src_y));
  3192.                                         $ratio_crop array();
  3193.                                         $ratio_crop['x'$this->image_dst_x $this->image_x;
  3194.                                         if (strpos($this->image_ratio_crop'l'!== false{
  3195.                                             $ratio_crop['l'0;
  3196.                                             $ratio_crop['r'$ratio_crop['x'];
  3197.                                         else if (strpos($this->image_ratio_crop'r'!== false{
  3198.                                             $ratio_crop['l'$ratio_crop['x'];
  3199.                                             $ratio_crop['r'0;
  3200.                                         else {
  3201.                                             $ratio_crop['l'round($ratio_crop['x']/2);
  3202.                                             $ratio_crop['r'$ratio_crop['x'$ratio_crop['l'];
  3203.                                         }
  3204.                                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;ratio_crop_x         : ' $ratio_crop['x'' (' $ratio_crop['l'';' $ratio_crop['r'')<br />';
  3205.                                         if (is_null($this->image_crop)) $this->image_crop array(0000);
  3206.                                     else {
  3207.                                         $this->image_dst_x $this->image_x;
  3208.                                         $this->image_dst_y intval($this->image_src_y*($this->image_x $this->image_src_x));
  3209.                                         $ratio_crop array();
  3210.                                         $ratio_crop['y'$this->image_dst_y $this->image_y;
  3211.                                         if (strpos($this->image_ratio_crop't'!== false{
  3212.                                             $ratio_crop['t'0;
  3213.                                             $ratio_crop['b'$ratio_crop['y'];
  3214.                                         else if (strpos($this->image_ratio_crop'b'!== false{
  3215.                                             $ratio_crop['t'$ratio_crop['y'];
  3216.                                             $ratio_crop['b'0;
  3217.                                         else {
  3218.                                             $ratio_crop['t'round($ratio_crop['y']/2);
  3219.                                             $ratio_crop['b'$ratio_crop['y'$ratio_crop['t'];
  3220.                                         }
  3221.                                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;ratio_crop_y         : ' $ratio_crop['y'' (' $ratio_crop['t'';' $ratio_crop['b'')<br />';
  3222.                                         if (is_null($this->image_crop)) $this->image_crop array(0000);
  3223.                                     }
  3224.                                 else if ($this->image_ratio_fill{
  3225.                                     if (!is_string($this->image_ratio_fill)) $this->image_ratio_fill '';
  3226.                                     $this->image_ratio_fill strtolower($this->image_ratio_fill);
  3227.                                     if (($this->image_src_x/$this->image_x($this->image_src_y/$this->image_y)) {
  3228.                                         $this->image_dst_y $this->image_y;
  3229.                                         $this->image_dst_x intval($this->image_src_x*($this->image_y $this->image_src_y));
  3230.                                         $ratio_crop array();
  3231.                                         $ratio_crop['x'$this->image_dst_x $this->image_x;
  3232.                                         if (strpos($this->image_ratio_fill'l'!== false{
  3233.                                             $ratio_crop['l'0;
  3234.                                             $ratio_crop['r'$ratio_crop['x'];
  3235.                                         else if (strpos($this->image_ratio_fill'r'!== false{
  3236.                                             $ratio_crop['l'$ratio_crop['x'];
  3237.                                             $ratio_crop['r'0;
  3238.                                         else {
  3239.                                             $ratio_crop['l'round($ratio_crop['x']/2);
  3240.                                             $ratio_crop['r'$ratio_crop['x'$ratio_crop['l'];
  3241.                                         }
  3242.                                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;ratio_fill_x         : ' $ratio_crop['x'' (' $ratio_crop['l'';' $ratio_crop['r'')<br />';
  3243.                                         if (is_null($this->image_crop)) $this->image_crop array(0000);
  3244.                                     else {
  3245.                                         $this->image_dst_x $this->image_x;
  3246.                                         $this->image_dst_y intval($this->image_src_y*($this->image_x $this->image_src_x));
  3247.                                         $ratio_crop array();
  3248.                                         $ratio_crop['y'$this->image_dst_y $this->image_y;
  3249.                                         if (strpos($this->image_ratio_fill't'!== false{
  3250.                                             $ratio_crop['t'0;
  3251.                                             $ratio_crop['b'$ratio_crop['y'];
  3252.                                         else if (strpos($this->image_ratio_fill'b'!== false{
  3253.                                             $ratio_crop['t'$ratio_crop['y'];
  3254.                                             $ratio_crop['b'0;
  3255.                                         else {
  3256.                                             $ratio_crop['t'round($ratio_crop['y']/2);
  3257.                                             $ratio_crop['b'$ratio_crop['y'$ratio_crop['t'];
  3258.                                         }
  3259.                                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;ratio_fill_y         : ' $ratio_crop['y'' (' $ratio_crop['t'';' $ratio_crop['b'')<br />';
  3260.                                         if (is_null($this->image_crop)) $this->image_crop array(0000);
  3261.                                     }
  3262.                                 else {
  3263.                                     if (($this->image_src_x/$this->image_x($this->image_src_y/$this->image_y)) {
  3264.                                         $this->image_dst_x $this->image_x;
  3265.                                         $this->image_dst_y intval($this->image_src_y*($this->image_x $this->image_src_x));
  3266.                                     else {
  3267.                                         $this->image_dst_y $this->image_y;
  3268.                                         $this->image_dst_x intval($this->image_src_x*($this->image_y $this->image_src_y));
  3269.                                     }
  3270.                                 }
  3271.                             else {
  3272.                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;doesn\'t calculate x/y sizes<br />';
  3273.                                 $this->image_dst_x $this->image_src_x;
  3274.                                 $this->image_dst_y $this->image_src_y;
  3275.                             }
  3276.                         else {
  3277.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;use plain sizes<br />';
  3278.                             $this->image_dst_x $this->image_x;
  3279.                             $this->image_dst_y $this->image_y;
  3280.                         }
  3281.  
  3282.                         if ($this->image_dst_x 1$this->image_dst_x 1;
  3283.                         if ($this->image_dst_y 1$this->image_dst_y 1;
  3284.                         $image_dst $this->imagecreatenew($this->image_dst_x$this->image_dst_y);
  3285.  
  3286.                         if ($gd_version >= 2{
  3287.                             $res imagecopyresampled($image_dst$image_src0000$this->image_dst_x$this->image_dst_y$this->image_src_x$this->image_src_y);
  3288.                         else {
  3289.                             $res imagecopyresized($image_dst$image_src0000$this->image_dst_x$this->image_dst_y$this->image_src_x$this->image_src_y);
  3290.                         }
  3291.  
  3292.                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;resized image object created<br />';
  3293.                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_src_x y        : ' $this->image_src_x ' x ' $this->image_src_y '<br />';
  3294.                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_dst_x y        : ' $this->image_dst_x ' x ' $this->image_dst_y '<br />';
  3295.  
  3296.                     else {
  3297.                         // we only convert, so we link the dst image to the src image
  3298.                         $image_dst $image_src;
  3299.                     }
  3300.  
  3301.                     // crop imag (and also crops if image_ratio_crop is used)
  3302.                     if ((!empty($this->image_crop|| !is_null($ratio_crop))) {
  3303.                         if (is_array($this->image_crop)) {
  3304.                             $vars $this->image_crop;
  3305.                         else {
  3306.                             $vars explode(' '$this->image_crop);
  3307.                         }
  3308.                         if (sizeof($vars== 4{
  3309.                             $ct $vars[0]$cr $vars[1]$cb $vars[2]$cl $vars[3];
  3310.                         else if (sizeof($vars== 2{
  3311.                             $ct $vars[0]$cr $vars[1]$cb $vars[0]$cl $vars[1];
  3312.                         else {
  3313.                             $ct $vars[0]$cr $vars[0]$cb $vars[0]$cl $vars[0];
  3314.                         }
  3315.                         if (strpos($ct'%')>0$ct $this->image_dst_y (str_replace('%','',$ct100);
  3316.                         if (strpos($cr'%')>0$cr $this->image_dst_x (str_replace('%','',$cr100);
  3317.                         if (strpos($cb'%')>0$cb $this->image_dst_y (str_replace('%','',$cb100);
  3318.                         if (strpos($cl'%')>0$cl $this->image_dst_x (str_replace('%','',$cl100);
  3319.                         if (strpos($ct'px')>0$ct str_replace('px','',$ct);
  3320.                         if (strpos($cr'px')>0$cr str_replace('px','',$cr);
  3321.                         if (strpos($cb'px')>0$cb str_replace('px','',$cb);
  3322.                         if (strpos($cl'px')>0$cl str_replace('px','',$cl);
  3323.                         $ct = (int) $ct;
  3324.                         $cr = (int) $cr;
  3325.                         $cb = (int) $cb;
  3326.                         $cl = (int) $cl;
  3327.                         // we adjust the cropping if we use image_ratio_crop
  3328.                         if (!is_null($ratio_crop)) {
  3329.                             if (array_key_exists('t'$ratio_crop)) $ct += $ratio_crop['t'];
  3330.                             if (array_key_exists('r'$ratio_crop)) $cr += $ratio_crop['r'];
  3331.                             if (array_key_exists('b'$ratio_crop)) $cb += $ratio_crop['b'];
  3332.                             if (array_key_exists('l'$ratio_crop)) $cl += $ratio_crop['l'];
  3333.                         }
  3334.                         $this->log .= '- crop image : ' $ct ' ' $cr ' ' $cb ' ' $cl ' <br />';
  3335.                         $this->image_dst_x $this->image_dst_x $cl $cr;
  3336.                         $this->image_dst_y $this->image_dst_y $ct $cb;
  3337.                         if ($this->image_dst_x 1$this->image_dst_x 1;
  3338.                         if ($this->image_dst_y 1$this->image_dst_y 1;
  3339.                         $tmp $this->imagecreatenew($this->image_dst_x$this->image_dst_y);
  3340.  
  3341.                         // we copy the image into the recieving image
  3342.                         imagecopy($tmp$image_dst00$cl$ct$this->image_dst_x$this->image_dst_y);
  3343.  
  3344.                         // if we crop with negative margins, we have to make sure the extra bits are the right color, or transparent
  3345.                         if ($ct || $cr || $cb || $cl {
  3346.                             // use the background color if present
  3347.                             if (!empty($this->image_background_color)) {
  3348.                                 list($red$green$blue$this->getcolors($this->image_background_color);
  3349.                                 $fill imagecolorallocate($tmp$red$green$blue);
  3350.                             else {
  3351.                                 $fill imagecolorallocatealpha($tmp000127);
  3352.                             }
  3353.                             // fills eventual negative margins
  3354.                             if ($ct 0imagefilledrectangle($tmp00$this->image_dst_x-$ct$fill);
  3355.                             if ($cr 0imagefilledrectangle($tmp$this->image_dst_x $cr0$this->image_dst_x$this->image_dst_y$fill);
  3356.                             if ($cb 0imagefilledrectangle($tmp0$this->image_dst_y $cb$this->image_dst_x$this->image_dst_y$fill);
  3357.                             if ($cl 0imagefilledrectangle($tmp00-$cl$this->image_dst_y$fill);
  3358.                         }
  3359.  
  3360.                         // we transfert tmp into image_dst
  3361.                         $image_dst $this->imagetransfer($tmp$image_dst);
  3362.                     }
  3363.  
  3364.  
  3365.                     // flip image
  3366.                     if ($gd_version >= && !empty($this->image_flip)) {
  3367.                         $this->image_flip strtolower($this->image_flip);
  3368.                         $this->log .= '- flip image : ' $this->image_flip '<br />';
  3369.                         $tmp $this->imagecreatenew($this->image_dst_x$this->image_dst_y);
  3370.                         for ($x 0$x $this->image_dst_x$x++{
  3371.                             for ($y 0$y $this->image_dst_y$y++){
  3372.                                 if (strpos($this->image_flip'v'!== false{
  3373.                                     imagecopy($tmp$image_dst$this->image_dst_x $x 1$y$x$y11);
  3374.                                 else {
  3375.                                     imagecopy($tmp$image_dst$x$this->image_dst_y $y 1$x$y11);
  3376.                                 }
  3377.                             }
  3378.                         }
  3379.                         // we transfert tmp into image_dst
  3380.                         $image_dst $this->imagetransfer($tmp$image_dst);
  3381.                     }
  3382.  
  3383.                     // rotate image
  3384.                     if ($gd_version >= && is_numeric($this->image_rotate)) {
  3385.                         if (!in_array($this->image_rotatearray(090180270))) $this->image_rotate 0;
  3386.                         if ($this->image_rotate != 0{
  3387.                             if ($this->image_rotate == 90 || $this->image_rotate == 270{
  3388.                                 $tmp $this->imagecreatenew($this->image_dst_y$this->image_dst_x);
  3389.                             else {
  3390.                                 $tmp $this->imagecreatenew($this->image_dst_x$this->image_dst_y);
  3391.                             }
  3392.                             $this->log .= '- rotate image : ' $this->image_rotate '<br />';
  3393.                             for ($x 0$x $this->image_dst_x$x++{
  3394.                                 for ($y 0$y $this->image_dst_y$y++){
  3395.                                     if ($this->image_rotate == 90{
  3396.                                         imagecopy($tmp$image_dst$y$x$x$this->image_dst_y $y 111);
  3397.                                     else if ($this->image_rotate == 180{
  3398.                                         imagecopy($tmp$image_dst$x$y$this->image_dst_x $x 1$this->image_dst_y $y 111);
  3399.                                     else if ($this->image_rotate == 270{
  3400.                                         imagecopy($tmp$image_dst$y$x$this->image_dst_x $x 1$y11);
  3401.                                     else {
  3402.                                         imagecopy($tmp$image_dst$x$y$x$y11);
  3403.                                     }
  3404.                                 }
  3405.                             }
  3406.                             if ($this->image_rotate == 90 || $this->image_rotate == 270{
  3407.                                 $t $this->image_dst_y;
  3408.                                 $this->image_dst_y $this->image_dst_x;
  3409.                                 $this->image_dst_x $t;
  3410.                             }
  3411.                             // we transfert tmp into image_dst
  3412.                             $image_dst $this->imagetransfer($tmp$image_dst);
  3413.                         }
  3414.                     }
  3415.  
  3416.                     // add color overlay
  3417.                    if ($gd_version >= && (is_numeric($this->image_overlay_percent&& $this->image_overlay_percent && !empty($this->image_overlay_color))) {
  3418.                         $this->log .= '- apply color overlay<br />';
  3419.                         list($red$green$blue$this->getcolors($this->image_overlay_color);
  3420.                         $filter imagecreatetruecolor($this->image_dst_x$this->image_dst_y);
  3421.                         $color imagecolorallocate($filter$red$green$blue);
  3422.                         imagefilledrectangle($filter00$this->image_dst_x$this->image_dst_y$color);
  3423.                         $this->imagecopymergealpha($image_dst$filter0000$this->image_dst_x$this->image_dst_y$this->image_overlay_percent);
  3424.                         imagedestroy($filter);
  3425.                     }
  3426.  
  3427.                     // add brightness, contrast and tint, turns to greyscale and inverts colors
  3428.                     if ($gd_version >= && ($this->image_negative || $this->image_greyscale || is_numeric($this->image_threshold)|| is_numeric($this->image_brightness|| is_numeric($this->image_contrast|| !empty($this->image_tint_color))) {
  3429.                         $this->log .= '- apply tint, light, contrast correction, negative, greyscale and threshold<br />';
  3430.                         if (!empty($this->image_tint_color)) list($tint_red$tint_green$tint_blue$this->getcolors($this->image_tint_color);
  3431.                         imagealphablending($image_dsttrue);
  3432.                         for($y=0$y $this->image_dst_y$y++{
  3433.                             for($x=0$x $this->image_dst_x$x++{
  3434.                                 if ($this->image_greyscale{
  3435.                                     $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3436.                                     $r $g $b round((0.2125 $pixel['red'](0.7154 $pixel['green'](0.0721 $pixel['blue']));
  3437.                                     $color imagecolorallocatealpha($image_dst$r$g$b$pixel['alpha']);
  3438.                                     imagesetpixel($image_dst$x$y$color);
  3439.                                 }
  3440.                                 if (is_numeric($this->image_threshold)) {
  3441.                                     $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3442.                                     $c (round($pixel['red'$pixel['green'$pixel['blue']3127;
  3443.                                     $r $g $b ($c $this->image_threshold 255 0);
  3444.                                     $color imagecolorallocatealpha($image_dst$r$g$b$pixel['alpha']);
  3445.                                     imagesetpixel($image_dst$x$y$color);
  3446.                                 }
  3447.                                 if (is_numeric($this->image_brightness)) {
  3448.                                     $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3449.                                     $r max(min(round($pixel['red'(($this->image_brightness 2)))255)0);
  3450.                                     $g max(min(round($pixel['green'(($this->image_brightness 2)))255)0);
  3451.                                     $b max(min(round($pixel['blue'(($this->image_brightness 2)))255)0);
  3452.                                     $color imagecolorallocatealpha($image_dst$r$g$b$pixel['alpha']);
  3453.                                     imagesetpixel($image_dst$x$y$color);
  3454.                                 }
  3455.                                 if (is_numeric($this->image_contrast)) {
  3456.                                     $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3457.                                     $r max(min(round(($this->image_contrast 128$pixel['red'128)255)0);
  3458.                                     $g max(min(round(($this->image_contrast 128$pixel['green'128)255)0);
  3459.                                     $b max(min(round(($this->image_contrast 128$pixel['blue'128)255)0);
  3460.                                     $color imagecolorallocatealpha($image_dst$r$g$b$pixel['alpha']);
  3461.                                     imagesetpixel($image_dst$x$y$color);
  3462.                                 }
  3463.                                 if (!empty($this->image_tint_color)) {
  3464.                                     $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3465.                                     $r min(round($tint_red $pixel['red'169)255);
  3466.                                     $g min(round($tint_green $pixel['green'169)255);
  3467.                                     $b min(round($tint_blue $pixel['blue'169)255);
  3468.                                     $color imagecolorallocatealpha($image_dst$r$g$b$pixel['alpha']);
  3469.                                     imagesetpixel($image_dst$x$y$color);
  3470.                                 }
  3471.                                 if (!empty($this->image_negative)) {
  3472.                                     $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3473.                                     $r round(255 $pixel['red']);
  3474.                                     $g round(255 $pixel['green']);
  3475.                                     $b round(255 $pixel['blue']);
  3476.                                     $color imagecolorallocatealpha($image_dst$r$g$b$pixel['alpha']);
  3477.                                     imagesetpixel($image_dst$x$y$color);
  3478.                                 }
  3479.                             }
  3480.                         }
  3481.                     }
  3482.  
  3483.                     // adds a border
  3484.                     if ($gd_version >= && !empty($this->image_border)) {
  3485.                         if (is_array($this->image_border)) {
  3486.                             $vars $this->image_border;
  3487.                             $this->log .= '- add border : ' implode(' '$this->image_border'<br />';
  3488.                         else {
  3489.                             $this->log .= '- add border : ' $this->image_border '<br />';
  3490.                             $vars explode(' '$this->image_border);
  3491.                         }
  3492.                         if (sizeof($vars== 4{
  3493.                             $ct $vars[0]$cr $vars[1]$cb $vars[2]$cl $vars[3];
  3494.                         else if (sizeof($vars== 2{
  3495.                             $ct $vars[0]$cr $vars[1]$cb $vars[0]$cl $vars[1];
  3496.                         else {
  3497.                             $ct $vars[0]$cr $vars[0]$cb $vars[0]$cl $vars[0];
  3498.                         }
  3499.                         if (strpos($ct'%')>0$ct $this->image_dst_y (str_replace('%','',$ct100);
  3500.                         if (strpos($cr'%')>0$cr $this->image_dst_x (str_replace('%','',$cr100);
  3501.                         if (strpos($cb'%')>0$cb $this->image_dst_y (str_replace('%','',$cb100);
  3502.                         if (strpos($cl'%')>0$cl $this->image_dst_x (str_replace('%','',$cl100);
  3503.                         if (strpos($ct'px')>0$ct str_replace('px','',$ct);
  3504.                         if (strpos($cr'px')>0$cr str_replace('px','',$cr);
  3505.                         if (strpos($cb'px')>0$cb str_replace('px','',$cb);
  3506.                         if (strpos($cl'px')>0$cl str_replace('px','',$cl);
  3507.                         $ct = (int) $ct;
  3508.                         $cr = (int) $cr;
  3509.                         $cb = (int) $cb;
  3510.                         $cl = (int) $cl;
  3511.                         $this->image_dst_x $this->image_dst_x $cl $cr;
  3512.                         $this->image_dst_y $this->image_dst_y $ct $cb;
  3513.                         if (!empty($this->image_border_color)) list($red$green$blue$this->getcolors($this->image_border_color);
  3514.                         // we now create an image, that we fill with the border color
  3515.                         $tmp $this->imagecreatenew($this->image_dst_x$this->image_dst_y);
  3516.                         $background imagecolorallocatealpha($tmp$red$green$blue0);
  3517.                         imagefilledrectangle($tmp00$this->image_dst_x$this->image_dst_y$background);
  3518.                         // we then copy the source image into the new image, without merging so that only the border is actually kept
  3519.                         imagecopy($tmp$image_dst$cl$ct00$this->image_dst_x $cr $cl$this->image_dst_y $cb $ct);
  3520.                         // we transfert tmp into image_dst
  3521.                         $image_dst $this->imagetransfer($tmp$image_dst);
  3522.                     }
  3523.  
  3524.                     // add frame border
  3525.                     if (is_numeric($this->image_frame)) {
  3526.                         if (is_array($this->image_frame_colors)) {
  3527.                             $vars $this->image_frame_colors;
  3528.                             $this->log .= '- add frame : ' implode(' '$this->image_frame_colors'<br />';
  3529.                         else {
  3530.                             $this->log .= '- add frame : ' $this->image_frame_colors '<br />';
  3531.                             $vars explode(' '$this->image_frame_colors);
  3532.                         }
  3533.                         $nb sizeof($vars);
  3534.                         $this->image_dst_x $this->image_dst_x ($nb 2);
  3535.                         $this->image_dst_y $this->image_dst_y ($nb 2);
  3536.                         $tmp $this->imagecreatenew($this->image_dst_x$this->image_dst_y);
  3537.                         imagecopy($tmp$image_dst$nb$nb00$this->image_dst_x ($nb 2)$this->image_dst_y ($nb 2));
  3538.                         for ($i=0$i<$nb$i++{
  3539.                             list($red$green$blue$this->getcolors($vars[$i]);
  3540.                             $c imagecolorallocate($tmp$red$green$blue);
  3541.                             if ($this->image_frame == 1{
  3542.                                 imageline($tmp$i$i$this->image_dst_x $i -1$i$c);
  3543.                                 imageline($tmp$this->image_dst_x $i -1$this->image_dst_y $i -1$this->image_dst_x $i -1$i$c);
  3544.                                 imageline($tmp$this->image_dst_x $i -1$this->image_dst_y $i -1$i$this->image_dst_y $i -1$c);
  3545.                                 imageline($tmp$i$i$i$this->image_dst_y $i -1$c);
  3546.                             else {
  3547.                                 imageline($tmp$i$i$this->image_dst_x $i -1$i$c);
  3548.                                 imageline($tmp$this->image_dst_x $nb $i$this->image_dst_y $nb $i$this->image_dst_x $nb $i$nb $i$c);
  3549.                                 imageline($tmp$this->image_dst_x $nb $i$this->image_dst_y $nb $i$nb $i$this->image_dst_y $nb $i$c);
  3550.                                 imageline($tmp$i$i$i$this->image_dst_y $i -1$c);
  3551.                             }
  3552.                         }
  3553.                         // we transfert tmp into image_dst
  3554.                         $image_dst $this->imagetransfer($tmp$image_dst);
  3555.                     }
  3556.  
  3557.                     // add bevel border
  3558.                     if ($this->image_bevel 0{
  3559.                         if (empty($this->image_bevel_color1)) $this->image_bevel_color1 '#FFFFFF';
  3560.                         if (empty($this->image_bevel_color2)) $this->image_bevel_color2 '#000000';
  3561.                         list($red1$green1$blue1$this->getcolors($this->image_bevel_color1);
  3562.                         list($red2$green2$blue2$this->getcolors($this->image_bevel_color2);
  3563.                         $tmp $this->imagecreatenew($this->image_dst_x$this->image_dst_y);
  3564.                         imagecopy($tmp$image_dst0000$this->image_dst_x$this->image_dst_y);
  3565.                         imagealphablending($tmptrue);
  3566.                         for ($i=0$i<$this->image_bevel$i++{
  3567.                             $alpha round(($i $this->image_bevel127);
  3568.                             $c1 imagecolorallocatealpha($tmp$red1$green1$blue1$alpha);
  3569.                             $c2 imagecolorallocatealpha($tmp$red2$green2$blue2$alpha);
  3570.                             imageline($tmp$i$i$this->image_dst_x $i -1$i$c1);
  3571.                             imageline($tmp$this->image_dst_x $i -1$this->image_dst_y $i$this->image_dst_x $i -1$i$c2);
  3572.                             imageline($tmp$this->image_dst_x $i -1$this->image_dst_y $i -1$i$this->image_dst_y $i -1$c2);
  3573.                             imageline($tmp$i$i$i$this->image_dst_y $i -1$c1);
  3574.                         }
  3575.                         // we transfert tmp into image_dst
  3576.                         $image_dst $this->imagetransfer($tmp$image_dst);
  3577.                     }
  3578.  
  3579.                     // add watermark image
  3580.                     if ($this->image_watermark!='' && file_exists($this->image_watermark)) {
  3581.                         $this->log .= '- add watermark<br />';
  3582.                         $this->image_watermark_position strtolower($this->image_watermark_position);
  3583.                         $watermark_info getimagesize($this->image_watermark);
  3584.                         $watermark_type (array_key_exists(2$watermark_info$watermark_info[2null)// 1 = GIF, 2 = JPG, 3 = PNG
  3585.                         $watermark_checked false;
  3586.                         if ($watermark_type == IMAGETYPE_GIF{
  3587.                             if (!function_exists('imagecreatefromgif')) {
  3588.                                 $this->error $this->translate('watermark_no_create_support'array('GIF'));
  3589.                             else {
  3590.                                 $filter @imagecreatefromgif($this->image_watermark);
  3591.                                 if (!$filter{
  3592.                                     $this->error $this->translate('watermark_create_error'array('GIF'));
  3593.                                 else {
  3594.                                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;watermark source image is GIF<br />';
  3595.                                     $watermark_checked true;
  3596.                                 }
  3597.                             }
  3598.                         else if ($watermark_type == IMAGETYPE_JPEG{
  3599.                             if (!function_exists('imagecreatefromjpeg')) {
  3600.                                 $this->error $this->translate('watermark_no_create_support'array('JPEG'));
  3601.                             else {
  3602.                                 $filter @imagecreatefromjpeg($this->image_watermark);
  3603.                                 if (!$filter{
  3604.                                     $this->error $this->translate('watermark_create_error'array('JPEG'));
  3605.                                 else {
  3606.                                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;watermark source image is JPEG<br />';
  3607.                                     $watermark_checked true;
  3608.                                 }
  3609.                             }
  3610.                         else if ($watermark_type == IMAGETYPE_PNG{
  3611.                             if (!function_exists('imagecreatefrompng')) {
  3612.                                 $this->error $this->translate('watermark_no_create_support'array('PNG'));
  3613.                             else {
  3614.                                 $filter @imagecreatefrompng($this->image_watermark);
  3615.                                 if (!$filter{
  3616.                                     $this->error $this->translate('watermark_create_error'array('PNG'));
  3617.                                 else {
  3618.                                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;watermark source image is PNG<br />';
  3619.                                     $watermark_checked true;
  3620.                                 }
  3621.                             }
  3622.                         else if ($watermark_type == IMAGETYPE_BMP{
  3623.                             if (!method_exists($this'imagecreatefrombmp')) {
  3624.                                 $this->error $this->translate('watermark_no_create_support'array('BMP'));
  3625.                             else {
  3626.                                 $filter @$this->imagecreatefrombmp($this->image_watermark);
  3627.                                 if (!$filter{
  3628.                                     $this->error $this->translate('watermark_create_error'array('BMP'));
  3629.                                 else {
  3630.                                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;watermark source image is BMP<br />';
  3631.                                     $watermark_checked true;
  3632.                                 }
  3633.                             }
  3634.                         else {
  3635.                             $this->error $this->translate('watermark_invalid');
  3636.                         }
  3637.                         if ($watermark_checked{
  3638.                             $watermark_width  imagesx($filter);
  3639.                             $watermark_height imagesy($filter);
  3640.                             $watermark_x 0;
  3641.                             $watermark_y 0;
  3642.                             if (is_numeric($this->image_watermark_x)) {
  3643.                                 if ($this->image_watermark_x 0{
  3644.                                     $watermark_x $this->image_dst_x $watermark_width $this->image_watermark_x;
  3645.                                 else {
  3646.                                     $watermark_x $this->image_watermark_x;
  3647.                                 }
  3648.                             else {
  3649.                                 if (strpos($this->image_watermark_position'r'!== false{
  3650.                                     $watermark_x $this->image_dst_x $watermark_width;
  3651.                                 else if (strpos($this->image_watermark_position'l'!== false{
  3652.                                     $watermark_x 0;
  3653.                                 else {
  3654.                                     $watermark_x ($this->image_dst_x $watermark_width2;
  3655.                                 }
  3656.                             }
  3657.                             if (is_numeric($this->image_watermark_y)) {
  3658.                                 if ($this->image_watermark_y 0{
  3659.                                     $watermark_y $this->image_dst_y $watermark_height $this->image_watermark_y;
  3660.                                 else {
  3661.                                     $watermark_y $this->image_watermark_y;
  3662.                                 }
  3663.                             else {
  3664.                                 if (strpos($this->image_watermark_position'b'!== false{
  3665.                                     $watermark_y $this->image_dst_y $watermark_height;
  3666.                                 else if (strpos($this->image_watermark_position't'!== false{
  3667.                                     $watermark_y 0;
  3668.                                 else {
  3669.                                     $watermark_y ($this->image_dst_y $watermark_height2;
  3670.                                 }
  3671.                             }
  3672.                             imagecopyresampled ($image_dst$filter$watermark_x$watermark_y00$watermark_width$watermark_height$watermark_width$watermark_height);
  3673.                         else {
  3674.                             $this->error $this->translate('watermark_invalid');
  3675.                         }
  3676.                     }
  3677.  
  3678.                     // add text
  3679.                     if (!empty($this->image_text)) {
  3680.                         $this->log .= '- add text<br />';
  3681.  
  3682.                         // calculate sizes in human readable format
  3683.                         $src_size       $this->file_src_size 1024;
  3684.                         $src_size_mb    number_format($src_size 10241"."" ");
  3685.                         $src_size_kb    number_format($src_size1"."" ");
  3686.                         $src_size_human ($src_size 1024 $src_size_mb " MB" $src_size_kb " kb");
  3687.  
  3688.                         $this->image_text str_replace(
  3689.                             array('[src_name]',
  3690.                                   '[src_name_body]',
  3691.                                   '[src_name_ext]',
  3692.                                   '[src_pathname]',
  3693.                                   '[src_mime]',
  3694.                                   '[src_size]',
  3695.                                   '[src_size_kb]',
  3696.                                   '[src_size_mb]',
  3697.                                   '[src_size_human]',
  3698.                                   '[src_x]',
  3699.                                   '[src_y]',
  3700.                                   '[src_pixels]',
  3701.                                   '[src_type]',
  3702.                                   '[src_bits]',
  3703.                                   '[dst_path]',
  3704.                                   '[dst_name_body]',
  3705.                                   '[dst_name_ext]',
  3706.                                   '[dst_name]',
  3707.                                   '[dst_pathname]',
  3708.                                   '[dst_x]',
  3709.                                   '[dst_y]',
  3710.                                   '[date]',
  3711.                                   '[time]',
  3712.                                   '[host]',
  3713.                                   '[server]',
  3714.                                   '[ip]',
  3715.                                   '[gd_version]'),
  3716.                             array($this->file_src_name,
  3717.                                   $this->file_src_name_body,
  3718.                                   $this->file_src_name_ext,
  3719.                                   $this->file_src_pathname,
  3720.                                   $this->file_src_mime,
  3721.                                   $this->file_src_size,
  3722.                                   $src_size_kb,
  3723.                                   $src_size_mb,
  3724.                                   $src_size_human,
  3725.                                   $this->image_src_x,
  3726.                                   $this->image_src_y,
  3727.                                   $this->image_src_pixels,
  3728.                                   $this->image_src_type,
  3729.                                   $this->image_src_bits,
  3730.                                   $this->file_dst_path,
  3731.                                   $this->file_dst_name_body,
  3732.                                   $this->file_dst_name_ext,
  3733.                                   $this->file_dst_name,
  3734.                                   $this->file_dst_pathname,
  3735.                                   $this->image_dst_x,
  3736.                                   $this->image_dst_y,
  3737.                                   date('Y-m-d'),
  3738.                                   date('H:i:s'),
  3739.                                   $_SERVER['HTTP_HOST'],
  3740.                                   $_SERVER['SERVER_NAME'],
  3741.                                   $_SERVER['REMOTE_ADDR'],
  3742.                                   $this->gdversion(true)),
  3743.                             $this->image_text);
  3744.  
  3745.                         if (!is_numeric($this->image_text_padding)) $this->image_text_padding 0;
  3746.                         if (!is_numeric($this->image_text_line_spacing)) $this->image_text_line_spacing 0;
  3747.                         if (!is_numeric($this->image_text_padding_x)) $this->image_text_padding_x $this->image_text_padding;
  3748.                         if (!is_numeric($this->image_text_padding_y)) $this->image_text_padding_y $this->image_text_padding;
  3749.                         $this->image_text_position strtolower($this->image_text_position);
  3750.                         $this->image_text_direction strtolower($this->image_text_direction);
  3751.                         $this->image_text_alignment strtolower($this->image_text_alignment);
  3752.  
  3753.                         // if the font is a string, we assume that we might want to load a font
  3754.                         if (!is_numeric($this->image_text_font&& strlen($this->image_text_font&& substr(strtolower($this->image_text_font)-4== '.gdf'{
  3755.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;try to load font ' $this->image_text_font '... ';
  3756.                             if ($this->image_text_font @imageloadfont($this->image_text_font)) {
  3757.                                 $this->log .=  'success<br />';
  3758.                             else {
  3759.                                 $this->log .=  'error<br />';
  3760.                                 $this->image_text_font 5;
  3761.                             }
  3762.                         }
  3763.  
  3764.                         $text explode("\n"$this->image_text);
  3765.                         $char_width imagefontwidth($this->image_text_font);
  3766.                         $char_height imagefontheight($this->image_text_font);
  3767.                         $text_height 0;
  3768.                         $text_width 0;
  3769.                         $line_height 0;
  3770.                         $line_width 0;
  3771.  
  3772.                         foreach ($text as $k => $v{
  3773.                             if ($this->image_text_direction == 'v'{
  3774.                                 $h ($char_width strlen($v));
  3775.                                 if ($h $text_height$text_height $h;
  3776.                                 $line_width $char_height;
  3777.                                 $text_width += $line_width ($k (sizeof($text)-1$this->image_text_line_spacing 0);
  3778.                             else {
  3779.                                 $w ($char_width strlen($v));
  3780.                                 if ($w $text_width$text_width $w;
  3781.                                 $line_height $char_height;
  3782.                                 $text_height += $line_height ($k (sizeof($text)-1$this->image_text_line_spacing 0);
  3783.                             }
  3784.                         }
  3785.                         $text_width  += ($this->image_text_padding_x);
  3786.                         $text_height += ($this->image_text_padding_y);
  3787.                         $text_x 0;
  3788.                         $text_y 0;
  3789.                         if (is_numeric($this->image_text_x)) {
  3790.                             if ($this->image_text_x 0{
  3791.                                 $text_x $this->image_dst_x $text_width $this->image_text_x;
  3792.                             else {
  3793.                                 $text_x $this->image_text_x;
  3794.                             }
  3795.                         else {
  3796.                             if (strpos($this->image_text_position'r'!== false{
  3797.                                 $text_x $this->image_dst_x $text_width;
  3798.                             else if (strpos($this->image_text_position'l'!== false{
  3799.                                 $text_x 0;
  3800.                             else {
  3801.                                 $text_x ($this->image_dst_x $text_width2;
  3802.                             }
  3803.                         }
  3804.                         if (is_numeric($this->image_text_y)) {
  3805.                             if ($this->image_text_y 0{
  3806.                                 $text_y $this->image_dst_y $text_height $this->image_text_y;
  3807.                             else {
  3808.                                 $text_y $this->image_text_y;
  3809.                             }
  3810.                         else {
  3811.                             if (strpos($this->image_text_position'b'!== false{
  3812.                                 $text_y $this->image_dst_y $text_height;
  3813.                             else if (strpos($this->image_text_position't'!== false{
  3814.                                 $text_y 0;
  3815.                             else {
  3816.                                 $text_y ($this->image_dst_y $text_height2;
  3817.                             }
  3818.                         }
  3819.  
  3820.                         // add a background, maybe transparent
  3821.                         if (!empty($this->image_text_background)) {
  3822.                             list($red$green$blue$this->getcolors($this->image_text_background);
  3823.                             if ($gd_version >= && (is_numeric($this->image_text_background_percent)) && $this->image_text_background_percent >= && $this->image_text_background_percent <= 100{
  3824.                                 $filter imagecreatetruecolor($text_width$text_height);
  3825.                                 $background_color imagecolorallocate($filter$red$green$blue);
  3826.                                 imagefilledrectangle($filter00$text_width$text_height$background_color);
  3827.                                 $this->imagecopymergealpha($image_dst$filter$text_x$text_y00$text_width$text_height$this->image_text_background_percent);
  3828.                                 imagedestroy($filter);
  3829.                             else {
  3830.                                 $background_color imagecolorallocate($image_dst ,$red$green$blue);
  3831.                                 imagefilledrectangle($image_dst$text_x$text_y$text_x $text_width$text_y $text_height$background_color);
  3832.                             }
  3833.                         }
  3834.  
  3835.                         $text_x += $this->image_text_padding_x;
  3836.                         $text_y += $this->image_text_padding_y;
  3837.                         $t_width $text_width ($this->image_text_padding_x);
  3838.                         $t_height $text_height ($this->image_text_padding_y);
  3839.                         list($red$green$blue$this->getcolors($this->image_text_color);
  3840.  
  3841.                         // add the text, maybe transparent
  3842.                         if ($gd_version >= && (is_numeric($this->image_text_percent)) && $this->image_text_percent >= && $this->image_text_percent <= 100{
  3843.                             if ($t_width 0$t_width 0;
  3844.                             if ($t_height 0$t_height 0;
  3845.                             $filter $this->imagecreatenew($t_width$t_heightfalsetrue);
  3846.                             $text_color imagecolorallocate($filter ,$red$green$blue);
  3847.  
  3848.                             foreach ($text as $k => $v{
  3849.                                 if ($this->image_text_direction == 'v'{
  3850.                                     imagestringup($filter,
  3851.                                                   $this->image_text_font,
  3852.                                                   $k ($line_width  ($k && $k (sizeof($text)) $this->image_text_line_spacing 0)),
  3853.                                                   $text_height ($this->image_text_padding_y($this->image_text_alignment == 'l' (($t_height strlen($v$char_width($this->image_text_alignment == 'r' 2))) ,
  3854.                                                   $v,
  3855.                                                   $text_color);
  3856.                                 else {
  3857.                                     imagestring($filter,
  3858.                                                 $this->image_text_font,
  3859.                                                 ($this->image_text_alignment == 'l' (($t_width strlen($v$char_width($this->image_text_alignment == 'r' 2))),
  3860.                                                 $k ($line_height  ($k && $k (sizeof($text)) $this->image_text_line_spacing 0)),
  3861.                                                 $v,
  3862.                                                 $text_color);
  3863.                                 }
  3864.                             }
  3865.                             $this->imagecopymergealpha($image_dst$filter$text_x$text_y00$t_width$t_height$this->image_text_percent);
  3866.                             imagedestroy($filter);
  3867.  
  3868.                         else {
  3869.                             $text_color imageColorAllocate($image_dst ,$red$green$blue);
  3870.                             foreach ($text as $k => $v{
  3871.                                 if ($this->image_text_direction == 'v'{
  3872.                                     imagestringup($image_dst,
  3873.                                                   $this->image_text_font,
  3874.                                                   $text_x $k ($line_width  ($k && $k (sizeof($text)) $this->image_text_line_spacing 0)),
  3875.                                                   $text_y $text_height ($this->image_text_padding_y($this->image_text_alignment == 'l' (($t_height strlen($v$char_width($this->image_text_alignment == 'r' 2))),
  3876.                                                   $v,
  3877.                                                   $text_color);
  3878.                                 else {
  3879.                                     imagestring($image_dst,
  3880.                                                 $this->image_text_font,
  3881.                                                 $text_x ($this->image_text_alignment == 'l' (($t_width strlen($v$char_width($this->image_text_alignment == 'r' 2))),
  3882.                                                 $text_y $k ($line_height  ($k && $k (sizeof($text)) $this->image_text_line_spacing 0)),
  3883.                                                 $v,
  3884.                                                 $text_color);
  3885.                                 }
  3886.                             }
  3887.                         }
  3888.                     }
  3889.  
  3890.                     // add a reflection
  3891.                     if ($this->image_reflection_height{
  3892.                         $this->log .= '- add reflection : ' $this->image_reflection_height '<br />';
  3893.                         // we decode image_reflection_height, which can be a integer, a string in pixels or percentage
  3894.                         $image_reflection_height $this->image_reflection_height;
  3895.                         if (strpos($image_reflection_height'%')>0$image_reflection_height $this->image_dst_y (str_replace('%','',$image_reflection_height 100));
  3896.                         if (strpos($image_reflection_height'px')>0$image_reflection_height str_replace('px','',$image_reflection_height);
  3897.                         $image_reflection_height = (int) $image_reflection_height;
  3898.                         if ($image_reflection_height $this->image_dst_y$image_reflection_height $this->image_dst_y;
  3899.                         if (empty($this->image_reflection_opacity)) $this->image_reflection_opacity 60;
  3900.                         // create the new destination image
  3901.                         $tmp $this->imagecreatenew($this->image_dst_x$this->image_dst_y $image_reflection_height $this->image_reflection_spacetrue);
  3902.                         $transparency $this->image_reflection_opacity;
  3903.  
  3904.                         // copy the original image
  3905.                         imagecopy($tmp$image_dst0000$this->image_dst_x$this->image_dst_y ($this->image_reflection_space $this->image_reflection_space 0));
  3906.  
  3907.                         // we have to make sure the extra bit is the right color, or transparent
  3908.                         if ($image_reflection_height $this->image_reflection_space 0{
  3909.                             // use the background color if present
  3910.                             if (!empty($this->image_background_color)) {
  3911.                                 list($red$green$blue$this->getcolors($this->image_background_color);
  3912.                                 $fill imagecolorallocate($tmp$red$green$blue);
  3913.                             else {
  3914.                                 $fill imagecolorallocatealpha($tmp000127);
  3915.                             }
  3916.                             // fill in from the edge of the extra bit
  3917.                             imagefill($tmpround($this->image_dst_x 2)$this->image_dst_y $image_reflection_height $this->image_reflection_space 1$fill);
  3918.                         }
  3919.  
  3920.                         // copy the reflection
  3921.                         for ($y 0$y $image_reflection_height$y++{
  3922.                             for ($x 0$x $this->image_dst_x$x++{
  3923.                                 $pixel_b imagecolorsforindex($tmpimagecolorat($tmp$x$y $this->image_dst_y $this->image_reflection_space));
  3924.                                 $pixel_o imagecolorsforindex($image_dstimagecolorat($image_dst$x$this->image_dst_y $y ($this->image_reflection_space $this->image_reflection_space 0)));
  3925.                                 $alpha_o ($pixel_o['alpha'127);
  3926.                                 $alpha_b ($pixel_b['alpha'127);
  3927.                                 $opacity $alpha_o $transparency 100;
  3928.                                 if ($opacity 0{
  3929.                                     $red   round((($pixel_o['red']   $opacity($pixel_b['red']  $alpha_b($alpha_b $opacity));
  3930.                                     $green round((($pixel_o['green'$opacity($pixel_b['green']$alpha_b($alpha_b $opacity));
  3931.                                     $blue  round((($pixel_o['blue']  $opacity($pixel_b['blue'$alpha_b($alpha_b $opacity));
  3932.                                     $alpha ($opacity $alpha_b);
  3933.                                     if ($alpha 1$alpha 1;
  3934.                                     $alpha =  round(($alpha127);
  3935.                                     $color imagecolorallocatealpha($tmp$red$green$blue$alpha);
  3936.                                     imagesetpixel($tmp$x$y $this->image_dst_y $this->image_reflection_space$color);
  3937.                                 }
  3938.                             }
  3939.                             if ($transparency 0$transparency $transparency ($this->image_reflection_opacity $image_reflection_height);
  3940.                         }
  3941.  
  3942.                         // copy the resulting image into the destination image
  3943.                         $this->image_dst_y $this->image_dst_y $image_reflection_height $this->image_reflection_space;
  3944.                         $image_dst $this->imagetransfer($tmp$image_dst);
  3945.                     }
  3946.  
  3947.                     // reduce the JPEG image to a set desired size
  3948.                     if (is_numeric($this->jpeg_size&& $this->jpeg_size && ($this->image_convert == 'jpeg' || $this->image_convert == 'jpg')) {
  3949.                         // inspired by: JPEGReducer class version 1, 25 November 2004, Author: Huda M ElMatsani, justhuda at netscape dot net
  3950.                         $this->log .= '- JPEG desired file size : ' $this->jpeg_size '<br />';
  3951.                         // calculate size of each image. 75%, 50%, and 25% quality
  3952.                         ob_start()imagejpeg($image_dst,'',75);  $buffer ob_get_contents()ob_end_clean();
  3953.                         $size75 strlen($buffer);
  3954.                         ob_start()imagejpeg($image_dst,'',50);  $buffer ob_get_contents()ob_end_clean();
  3955.                         $size50 strlen($buffer);
  3956.                         ob_start()imagejpeg($image_dst,'',25);  $buffer ob_get_contents()ob_end_clean();
  3957.                         $size25 strlen($buffer);
  3958.  
  3959.                         // calculate gradient of size reduction by quality
  3960.                         $mgrad1 25 ($size50-$size25);
  3961.                         $mgrad2 25 ($size75-$size50);
  3962.                         $mgrad3 50 ($size75-$size25);
  3963.                         $mgrad  ($mgrad1 $mgrad2 $mgrad33;
  3964.                         // result of approx. quality factor for expected size
  3965.                         $q_factor round($mgrad ($this->jpeg_size $size5050);
  3966.  
  3967.                         if ($q_factor<1{
  3968.                             $this->jpeg_quality=1;
  3969.                         elseif ($q_factor>100{
  3970.                             $this->jpeg_quality=100;
  3971.                         else {
  3972.                             $this->jpeg_quality=$q_factor;
  3973.                         }
  3974.                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;JPEG quality factor set to ' $this->jpeg_quality '<br />';
  3975.                     }
  3976.  
  3977.                     // converts image from true color, and fix transparency if needed
  3978.                     $this->log .= '- converting...<br />';
  3979.                     switch($this->image_convert{
  3980.                         case 'gif':
  3981.                             // if the image is true color, we convert it to a palette
  3982.                             if (imageistruecolor($image_dst)) {
  3983.                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;true color to palette<br />';
  3984.                                 // creates a black and white mask
  3985.                                 $mask array(array());
  3986.                                 for ($x 0$x $this->image_dst_x$x++{
  3987.                                     for ($y 0$y $this->image_dst_y$y++{
  3988.                                         $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3989.                                         $mask[$x][$y$pixel['alpha'];
  3990.                                     }
  3991.                                 }
  3992.                                 list($red$green$blue$this->getcolors($this->image_default_color);
  3993.                                 // first, we merge the image with the background color, so we know which colors we will have
  3994.                                 for ($x 0$x $this->image_dst_x$x++{
  3995.                                     for ($y 0$y $this->image_dst_y$y++{
  3996.                                         if ($mask[$x][$y0){
  3997.                                             // we have some transparency. we combine the color with the default color
  3998.                                             $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  3999.                                             $alpha ($mask[$x][$y127);
  4000.                                             $pixel['red'round(($pixel['red'(-$alpha$red ($alpha)));
  4001.                                             $pixel['green'round(($pixel['green'(-$alpha$green ($alpha)));
  4002.                                             $pixel['blue'round(($pixel['blue'(-$alpha$blue ($alpha)));
  4003.                                             $color imagecolorallocate($image_dst$pixel['red']$pixel['green']$pixel['blue']);
  4004.                                             imagesetpixel($image_dst$x$y$color);
  4005.                                         }
  4006.                                     }
  4007.                                 }
  4008.                                 // transfrom the true color image into palette, with it merged default color in
  4009.                                 // we will have the best color possible, including the background
  4010.                                 if (empty($this->image_background_color)) {
  4011.                                     imagetruecolortopalette($image_dsttrue255);
  4012.                                     $transparency imagecolorallocate($image_dst2541253);
  4013.                                     imagecolortransparent($image_dst$transparency);
  4014.                                     // make the transparent areas transparent
  4015.                                     for ($x 0$x $this->image_dst_x$x++{
  4016.                                         for ($y 0$y $this->image_dst_y$y++{
  4017.                                             // we test wether we have enough opacity to justify keeping the color
  4018.                                             if ($mask[$x][$y120imagesetpixel($image_dst$x$y$transparency);
  4019.                                         }
  4020.                                     }
  4021.                                 }
  4022.                                 unset($mask);
  4023.                             }
  4024.                             break;
  4025.                         case 'jpg':
  4026.                         case 'bmp':
  4027.                             // if the image doesn't support any transparency, then we merge it with the default color
  4028.                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;fills in transparency with default color<br />';
  4029.                                 list($red$green$blue$this->getcolors($this->image_default_color);
  4030.                                 $transparency imagecolorallocate($image_dst$red$green$blue);
  4031.                                 // make the transaparent areas transparent
  4032.                                 for ($x 0$x $this->image_dst_x$x++{
  4033.                                     for ($y 0$y $this->image_dst_y$y++{
  4034.                                         // we test wether we have some transparency, in which case we will merge the colors
  4035.                                         $pixel imagecolorsforindex($image_dstimagecolorat($image_dst$x$y));
  4036.                                         if ($pixel['alpha'== 127{
  4037.                                             // we have full transparency. we make the pixel transparent
  4038.                                             imagesetpixel($image_dst$x$y$transparency);
  4039.                                         else if ($pixel['alpha'0{
  4040.                                             // we have some transparency. we combine the color with the default color
  4041.                                             $alpha ($pixel['alpha'127);
  4042.                                             $pixel['red'round(($pixel['red'(-$alpha$red ($alpha)));
  4043.                                             $pixel['green'round(($pixel['green'(-$alpha$green ($alpha)));
  4044.                                             $pixel['blue'round(($pixel['blue'(-$alpha$blue ($alpha)));
  4045.                                             $color imagecolorclosest($image_dst$pixel['red']$pixel['green']$pixel['blue']);
  4046.                                             imagesetpixel($image_dst$x$y$color);
  4047.                                         }
  4048.                                     }
  4049.                                 }
  4050.  
  4051.                             break;
  4052.                         default:
  4053.                             break;
  4054.                     }
  4055.  
  4056.                     // outputs image
  4057.                     $this->log .= '- saving image...<br />';
  4058.                     switch($this->image_convert{
  4059.                         case 'jpeg':
  4060.                         case 'jpg':
  4061.                             if (!$return_mode{
  4062.                                 $result @imagejpeg($image_dst$this->file_dst_pathname$this->jpeg_quality);
  4063.                             else {
  4064.                                 ob_start();
  4065.                                 $result @imagejpeg($image_dst''$this->jpeg_quality);
  4066.                                 $return_content ob_get_contents();
  4067.                                 ob_end_clean();
  4068.                             }
  4069.                             if (!$result{
  4070.                                 $this->processed false;
  4071.                                 $this->error $this->translate('file_create'array('JPEG'));
  4072.                             else {
  4073.                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;JPEG image created<br />';
  4074.                             }
  4075.                             break;
  4076.                         case 'png':
  4077.                             imagealphablending$image_dstfalse );
  4078.                             imagesavealpha$image_dsttrue );
  4079.                             if (!$return_mode{
  4080.                                 $result @imagepng($image_dst$this->file_dst_pathname);
  4081.                             else {
  4082.                                 ob_start();
  4083.                                 $result @imagepng($image_dst);
  4084.                                 $return_content ob_get_contents();
  4085.                                 ob_end_clean();
  4086.                             }
  4087.                             if (!$result{
  4088.                                 $this->processed false;
  4089.                                 $this->error $this->translate('file_create'array('PNG'));
  4090.                             else {
  4091.                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;PNG image created<br />';
  4092.                             }
  4093.                             break;
  4094.                         case 'gif':
  4095.                             if (!$return_mode{
  4096.                                 $result @imagegif($image_dst$this->file_dst_pathname);
  4097.                             else {
  4098.                                 ob_start();
  4099.                                 $result @imagegif($image_dst);
  4100.                                 $return_content ob_get_contents();
  4101.                                 ob_end_clean();
  4102.                             }
  4103.                             if (!$result{
  4104.                                 $this->processed false;
  4105.                                 $this->error $this->translate('file_create'array('GIF'));
  4106.                             else {
  4107.                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;GIF image created<br />';
  4108.                             }
  4109.                             break;
  4110.                         case 'bmp':
  4111.                             if (!$return_mode{
  4112.                                 $result $this->imagebmp($image_dst$this->file_dst_pathname);
  4113.                             else {
  4114.                                 ob_start();
  4115.                                 $result $this->imagebmp($image_dst);
  4116.                                 $return_content ob_get_contents();
  4117.                                 ob_end_clean();
  4118.                             }
  4119.                             if (!$result{
  4120.                                 $this->processed false;
  4121.                                 $this->error $this->translate('file_create'array('BMP'));
  4122.                             else {
  4123.                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;BMP image created<br />';
  4124.                             }
  4125.                             break;
  4126.  
  4127.                         default:
  4128.                             $this->processed false;
  4129.                             $this->error $this->translate('no_conversion_type');
  4130.                     }
  4131.                     if ($this->processed{
  4132.                         if (is_resource($image_src)) imagedestroy($image_src);
  4133.                         if (is_resource($image_dst)) imagedestroy($image_dst);
  4134.                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image objects destroyed<br />';
  4135.                     }
  4136.                 }
  4137.  
  4138.             else {
  4139.                 $this->log .= '- no image processing wanted<br />';
  4140.  
  4141.                 if (!$return_mode{
  4142.                     // copy the file to its final destination. we don't use move_uploaded_file here
  4143.                     // if we happen to have open_basedir restrictions, it is a temp file that we copy, not the original uploaded file
  4144.                     if (!copy($this->file_src_pathname$this->file_dst_pathname)) {
  4145.                         $this->processed false;
  4146.                         $this->error $this->translate('copy_failed');
  4147.                     }
  4148.                 else {
  4149.                     // returns the file, so that its content can be received by the caller
  4150.                     $return_content @file_get_contents($this->file_src_pathname);
  4151.                     if ($return_content === FALSE{
  4152.                         $this->processed false;
  4153.                         $this->error $this->translate('reading_failed');
  4154.                     }
  4155.                 }
  4156.             }
  4157.         }
  4158.  
  4159.         if ($this->processed{
  4160.             $this->log .= '- <b>process OK</b><br />';
  4161.  
  4162.         }
  4163.         // we reinit all the vars
  4164.         $this->init();
  4165.  
  4166.         // we may return the image content
  4167.         if ($return_modereturn $return_content;
  4168.  
  4169.     }
  4170.  
  4171.     /**
  4172.      * Deletes the uploaded file from its temporary location
  4173.      *
  4174.      * When PHP uploads a file, it stores it in a temporary location.
  4175.      * When you {@link process} the file, you actually copy the resulting file to the given location, it doesn't alter the original file.
  4176.      * Once you have processed the file as many times as you wanted, you can delete the uploaded file.
  4177.      * If there is open_basedir restrictions, the uploaded file is in fact a temporary file
  4178.      *
  4179.      * You might want not to use this function if you work on local files, as it will delete the source file
  4180.      *
  4181.      * @access public
  4182.      */
  4183.     function clean({
  4184.         $this->log .= '<b>cleanup</b><br />';
  4185.         $this->log .= '- delete temp file '  $this->file_src_pathname '<br />';
  4186.         @unlink($this->file_src_pathname);
  4187.     }
  4188.  
  4189.  
  4190.     /**
  4191.      * Opens a BMP image
  4192.      *
  4193.      * This function has been written by DHKold, and is used with permission of the author
  4194.      *
  4195.      * @access public
  4196.      */
  4197.     function imagecreatefrombmp($filename{
  4198.         if ($f1 fopen($filename,"rb")) return false;
  4199.  
  4200.         $file unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset"fread($f1,14));
  4201.         if ($file['file_type'!= 19778return false;
  4202.  
  4203.         $bmp unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel'.
  4204.                       '/Vcompression/Vsize_bitmap/Vhoriz_resolution'.
  4205.                       '/Vvert_resolution/Vcolors_used/Vcolors_important'fread($f1,40));
  4206.         $bmp['colors'pow(2,$bmp['bits_per_pixel']);
  4207.         if ($bmp['size_bitmap'== 0$bmp['size_bitmap'$file['file_size'$file['bitmap_offset'];
  4208.         $bmp['bytes_per_pixel'$bmp['bits_per_pixel']/8;
  4209.         $bmp['bytes_per_pixel2'ceil($bmp['bytes_per_pixel']);
  4210.         $bmp['decal'($bmp['width']*$bmp['bytes_per_pixel']/4);
  4211.         $bmp['decal'-= floor($bmp['width']*$bmp['bytes_per_pixel']/4);
  4212.         $bmp['decal'4-(4*$bmp['decal']);
  4213.         if ($bmp['decal'== 4$bmp['decal'0;
  4214.  
  4215.         $palette array();
  4216.         if ($bmp['colors'16777216{
  4217.             $palette unpack('V'.$bmp['colors']fread($f1,$bmp['colors']*4));
  4218.         }
  4219.  
  4220.         $im fread($f1,$bmp['size_bitmap']);
  4221.         $vide chr(0);
  4222.  
  4223.         $res imagecreatetruecolor($bmp['width'],$bmp['height']);
  4224.         $P 0;
  4225.         $Y $bmp['height']-1;
  4226.         while ($Y >= 0{
  4227.             $X=0;
  4228.             while ($X $bmp['width']{
  4229.                 if ($bmp['bits_per_pixel'== 24)
  4230.                     $color unpack("V",substr($im,$P,3).$vide);
  4231.                 elseif ($bmp['bits_per_pixel'== 16{
  4232.                     $color unpack("n",substr($im,$P,2));
  4233.                     $color[1$palette[$color[1]+1];
  4234.                 elseif ($bmp['bits_per_pixel'== 8{
  4235.                     $color unpack("n",$vide.substr($im,$P,1));
  4236.                     $color[1$palette[$color[1]+1];
  4237.                 elseif ($bmp['bits_per_pixel'== 4{
  4238.                     $color unpack("n",$vide.substr($im,floor($P),1));
  4239.                     if (($P*2)%== 0$color[1($color[1>> 4else $color[1($color[10x0F);
  4240.                     $color[1$palette[$color[1]+1];
  4241.                 elseif ($bmp['bits_per_pixel'== 1)  {
  4242.                     $color unpack("n",$vide.substr($im,floor($P),1));
  4243.                     if     (($P*8)%== 0$color[1=  $color[1]        >>7;
  4244.                     elseif (($P*8)%== 1$color[1($color[10x40)>>6;
  4245.                     elseif (($P*8)%== 2$color[1($color[10x20)>>5;
  4246.                     elseif (($P*8)%== 3$color[1($color[10x10)>>4;
  4247.                     elseif (($P*8)%== 4$color[1($color[10x8)>>3;
  4248.                     elseif (($P*8)%== 5$color[1($color[10x4)>>2;
  4249.                     elseif (($P*8)%== 6$color[1($color[10x2)>>1;
  4250.                     elseif (($P*8)%== 7$color[1($color[10x1);
  4251.                     $color[1$palette[$color[1]+1];
  4252.                 else
  4253.                     return FALSE;
  4254.                 imagesetpixel($res,$X,$Y,$color[1]);
  4255.                 $X++;
  4256.                 $P += $bmp['bytes_per_pixel'];
  4257.             }
  4258.             $Y--;
  4259.             $P+=$bmp['decal'];
  4260.         }
  4261.         fclose($f1);
  4262.         return $res;
  4263.     }
  4264.  
  4265.     /**
  4266.      * Saves a BMP image
  4267.      *
  4268.      * This function has been published on the PHP website, and can be used freely
  4269.      *
  4270.      * @access public
  4271.      */
  4272.     function imagebmp(&$im$filename ""{
  4273.  
  4274.         if (!$imreturn false;
  4275.         $w imagesx($im);
  4276.         $h imagesy($im);
  4277.         $result '';
  4278.  
  4279.         // if the image is not true color, we convert it first
  4280.         if (!imageistruecolor($im)) {
  4281.             $tmp imagecreatetruecolor($w$h);
  4282.             imagecopy($tmp$im0000$w$h);
  4283.             imagedestroy($im);
  4284.             $im $tmp;
  4285.         }
  4286.  
  4287.         $biBPLine $w 3;
  4288.         $biStride ($biBPLine 3~3;
  4289.         $biSizeImage $biStride $h;
  4290.         $bfOffBits 54;
  4291.         $bfSize $bfOffBits $biSizeImage;
  4292.  
  4293.         $result .= substr('BM'02);
  4294.         $result .=  pack ('VvvV'$bfSize00$bfOffBits);
  4295.         $result .= pack ('VVVvvVVVVVV'40$w$h1240$biSizeImage0000);
  4296.  
  4297.         $numpad $biStride $biBPLine;
  4298.         for ($y $h 1$y >= 0--$y{
  4299.             for ($x 0$x $w++$x{
  4300.                 $col imagecolorat ($im$x$y);
  4301.                 $result .=  substr(pack ('V'$col)03);
  4302.             }
  4303.             for ($i 0$i $numpad++$i)
  4304.                 $result .= pack ('C'0);
  4305.         }
  4306.  
  4307.         if($filename==""){
  4308.             echo $result;
  4309.         else {
  4310.             $file fopen($filename"wb");
  4311.             fwrite($file$result);
  4312.             fclose($file);
  4313.         }
  4314.         return true;
  4315.     }
  4316. }
  4317.  
  4318. ?>