Source for file class.upload.php 0.29

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