Source for file class.upload.php 0.32

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