Example #1
2
 function generateImage($token)
 {
     $iFont = 5;
     // Font ID
     $iSpacing = 2;
     // Spacing between characters
     $iDisplacement = 5;
     // Vertical chracter displacement
     // Establish font metric and image size
     $iCharWidth = ImageFontWidth($iFont);
     $iCharHeight = ImageFontHeight($iFont);
     $iWidth = strlen($token) * ($iCharWidth + $iSpacing);
     $iHeight = $iCharHeight + 2 * $iDisplacement;
     // Create the image
     $pic = ImageCreate($iWidth, $iHeight);
     // Allocate a background and foreground colour
     $col = array('white' => ImageColorAllocate($pic, 255, 255, 255), 'blue' => ImageColorAllocate($pic, 45, 45, 100), 'green' => ImageColorAllocate($pic, 45, 100, 45), 'red' => ImageColorAllocate($pic, 100, 45, 45), 'purple' => ImageColorAllocate($pic, 100, 45, 100), 'grey' => ImageColorAllocate($pic, 225, 225, 225), 'grey2' => ImageColorAllocate($pic, 200, 200, 200));
     for ($x = 0; $x < $iWidth; $x += 2) {
         for ($y = 0; $y < $iHeight; $y += 2) {
             ImageSetPixel($pic, $x, $y, $col['grey']);
         }
     }
     $iX = 1;
     for ($i = 0; $i < strlen($token); $i++) {
         ImageChar($pic, $iFont - 1, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col['grey2']);
         $iX += $iCharWidth + $iSpacing;
     }
     $iX = 2;
     $c = array('blue', 'green', 'red', 'purple');
     for ($i = 0; $i < strlen($token); $i++) {
         $colour = $c[rand(0, count($c) - 1)];
         ImageChar($pic, $iFont, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col[$colour]);
         $iX += $iCharWidth + $iSpacing;
     }
     for ($x = 1; $x < $iWidth; $x += 4) {
         for ($y = 1; $y < $iHeight; $y += 4) {
             ImageSetPixel($pic, $x, $y, $col['white']);
         }
     }
     // Draw some lines
     for ($i = 0; $i < 4; $i++) {
         ImageLine($pic, rand(0, $iWidth / 2), rand(0, $iHeight / 2), rand($iWidth / 2, $iWidth), rand($iHeight / 2, $iHeight), $col['white']);
     }
     ob_start();
     if (function_exists('imagejpeg')) {
         ImageJPEG($pic);
     } elseif (function_exists('imagepng')) {
         ImagePNG($pic);
     } else {
         ob_end_clean();
         return false;
     }
     $data = ob_get_contents();
     ob_end_clean();
     ImageDestroy($pic);
     return $data;
 }
Example #2
0
function ConvertToImage($content)
{
    $imageFile = ".counter.png";
    $relativePath = ".counter.png";
    $noOfChars = strlen($content);
    $charHeight = ImageFontHeight(5);
    $charWidth = ImageFontWidth(5);
    $strWidth = $charWidth * $noOfChars;
    $strHeight = $charHeight;
    //15 padding
    $imgWidth = $strWidth + 15;
    $imgHeight = $strHeight + 15;
    $imgCenterX = $imgWidth / 2;
    $imgCenterY = $imgHeight / 2;
    $im = ImageCreate($imgWidth, $imgHeight);
    $script = ImageColorAllocate($im, 0, 255, 0);
    $outercolor = ImageColorAllocate($im, 99, 140, 214);
    $innercolor = ImageColorAllocate($im, 0, 0, 0);
    ImageFilledRectangle($im, 0, 0, $imgWidth, $imgHeight, $outercolor);
    ImageFilledRectangle($im, 3, 3, $imgWidth - 4, $imgHeight - 4, $innercolor);
    //draw string
    $drawPosX = $imgCenterX - $strWidth / 2 + 1;
    $drawPosY = $imgCenterY - $strHeight / 2;
    ImageString($im, 5, $drawPosX, $drawPosY, $content, $script);
    //save image and return
    ImagePNG($im, $imageFile);
    return $relativePath;
}
 function gd_button()
 {
     if (file_exists($this->save_dir . $this->filename)) {
         return $this->filename;
     }
     $this->font_size = 5;
     $text_width = ImageFontWidth($this->font_size) * strlen($this->font_text);
     $text_height = ImageFontHeight($this->font_size);
     $this->width = $this->xspace * 2 + $text_width;
     $this->height = $this->yspace + $text_height;
     $this->xpos = $this->width / 2 - $text_width / 2;
     if ($this->xpos < 0) {
         $this->xpos = $this->xspace;
     }
     $this->ypos = $this->height / 2 - $text_height / 2;
     if ($this->ypos < 0) {
         $this->ypos = $this->yspace;
     }
     $this->button_init();
     $black = ImageColorAllocate($this->image, 0, 0, 0);
     ImageRectangle($this->image, 0, 0, $this->width - 1, $this->height - 1, $black);
     $white = ImageColorAllocate($this->image, 255, 255, 255);
     ImageRectangle($this->image, 0, 0, $this->width, $this->height, $white);
     ImageString($this->image, $this->font_size, intval($this->xpos + 1), intval($this->ypos), $this->font_text, $black);
     ImageString($this->image, $this->font_size, intval($this->xpos), intval($this->ypos - 1), $this->font_text, $white);
     return $this->save_button();
 }
Example #4
0
function image_create($image, $size, $x, $y, $text, $color, $maxwidth)
{
    $fontwidth = ImageFontWidth($size);
    $fontheight = ImageFontHeight($size);
    if ($maxwidth != NULL) {
        $maxchar = floor($maxwidth / $fontwidth);
        $text = wordwrap($text, $maxchar, "\n", 1);
    }
    $lines = explode("\n", $text);
    while (list($numl, $line) = each($lines)) {
        ImageString($image, $size, $x, $y, $line, $color);
        $y += $fontheight;
    }
}
Example #5
0
 function render_png($string, $hash)
 {
     $font = 4;
     $width = ImageFontWidth($font) * strlen($string);
     $height = ImageFontHeight($font);
     $im = @imagecreate($width, $height);
     $background_color = imagecolorallocate($im, 255, 255, 255);
     //white background
     $text_color = imagecolorallocate($im, 0, 0, 0);
     //black text
     imagecolortransparent($im, $background_color);
     imagestring($im, $font, 0, 0, $string, $text_color);
     $pngdata = imagepng($im, $this->CACHE_DIR . "/{$hash}.png");
     chdir($current_dir);
 }
function fatal_error($message)
{
    // send an image
    if (function_exists('ImageCreate')) {
        $width = ImageFontWidth(5) * strlen($message) + 10;
        $height = ImageFontHeight(5) + 10;
        if ($image = ImageCreate($width, $height)) {
            $background = ImageColorAllocate($image, 255, 255, 255);
            $text_color = ImageColorAllocate($image, 0, 0, 0);
            ImageString($image, 5, 5, 5, $message, $text_color);
            header('Content-type: image/png');
            ImagePNG($image);
            ImageDestroy($image);
            exit;
        }
    }
    // send 500 code
    header("HTTP/1.0 500 Internal Server Error");
    print $message;
    exit;
}
Example #7
0
function createImage($text, $width, $height, $font = 5)
{
    global $fontColor, $bgColor, $lineColor;
    if ($img = @ImageCreate($width, $height)) {
        list($R, $G, $B) = convertRGB($fontColor);
        $fontColor = ImageColorAllocate($img, $R, $G, $B);
        list($R, $G, $B) = convertRGB($bgColor);
        $bgColor = ImageColorAllocate($img, $R, $G, $B);
        list($R, $G, $B) = convertRGB($lineColor);
        $lineColor = ImageColorAllocate($img, $R, $G, $B);
        ImageFill($img, 0, 0, $bgColor);
        for ($i = 0; $i <= $width; $i += 5) {
            @ImageLine($img, $i, 0, $i, $height, $lineColor);
        }
        for ($i = 0; $i <= $height; $i += 5) {
            @ImageLine($img, 0, $i, $width, $i, $lineColor);
        }
        $hcenter = $width / 2;
        $vcenter = $height / 2;
        $x = round($hcenter - ImageFontWidth($font) * strlen($text) / 2);
        $y = round($vcenter - ImageFontHeight($font) / 2);
        ImageString($img, $font, $x, $y, $text, $fontColor);
        if (function_exists('ImagePNG')) {
            header('Content-Type: image/png');
            @ImagePNG($img);
        } else {
            if (function_exists('ImageGIF')) {
                header('Content-Type: image/gif');
                @ImageGIF($img);
            } else {
                if (function_exists('ImageJPEG')) {
                    header('Content-Type: image/jpeg');
                    @ImageJPEG($img);
                }
            }
        }
        ImageDestroy($img);
    }
}
Example #8
0
function ts_gfx($ts_random)
{
    global $site_key;
    $datekey = date("F j");
    $rcode = hexdec(md5($_SERVER[HTTP_USER_AGENT] . $sitekey . $ts_random . $datekey));
    $code = substr($rcode, 2, 6);
    $circles = 5;
    $lines = 1;
    $width = 100;
    $height = 40;
    $font = 5;
    $fontwidth = ImageFontWidth($font) * strlen($string);
    $fontheight = ImageFontHeight($font);
    $im = @imagecreate($width, $height);
    $background_color = imagecolorallocate($im, 255, 138, 0);
    $text_color = imagecolorallocate($im, rand(200, 255), rand(200, 255), rand(200, 255));
    // Random Text
    #rgb(1%, 51%, 87%)
    $r = 0.87;
    $g = 0.51;
    $b = 0.0;
    for ($i = 1; $i <= $circles; $i++) {
        $value = rand(200, 255);
        $randomcolor = imagecolorallocate($im, $value * $r, $value * $g, $value * $b);
        imagefilledellipse($im, rand(0, $width - 20), rand(0, $height - 6), rand(15, 70), rand(15, 70), $randomcolor);
    }
    imagerectangle($im, 0, 0, $width - 1, $height - 1, $text_color);
    imagestring($im, $font, 22, 12, $code, $text_color);
    for ($i = 0; $i < $lines; $i++) {
        $y1 = rand(14, 23);
        $y2 = rand(15, 24);
        $randomcolor = imagecolorallocate($im, rand(100, 255), 0, rand(100, 255));
        imageline($im, 0, $y1, $width, $y2, $randomcolor);
    }
    header("Content-type: image/jpeg");
    imagejpeg($im, '', 85);
    ImageDestroy($im);
    die;
}
 function print_image($text)
 {
     $w = 50;
     $image = imagecreate($w, 25);
     $light = ImageColorAllocate($image, 255, 255, 0);
     $dark = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 0, 0, 0);
     ImageFill($image, 0, 0, $light);
     $width_two = ImageFontWidth(5) * strlen($text);
     $height = ImageFontHeight(100);
     $width = ($w - $width_two) / 2;
     # vertical lines
     for ($x = 0; $x <= 100; $x += 10) {
         ImageLine($image, $x, 0, $x, 100, $dark);
     }
     # horizontal lines
     for ($x = 0; $x <= 100; $x += 10) {
         ImageLine($image, 0, $x, 100, $x, $dark);
     }
     ImageString($image, 5, $width, 4, $text, $dark);
     ImagePNG($image, '', 80);
     ImageDestroy($image);
 }
Example #10
0
 /**
  * Get the height of a text.
  * 
  * Note! This method can give some peculiar results, since ImageTTFBBox() returns the total
  * bounding box of a text, where ImageTTF() writes the text on the baseline of the text, that
  * is 'g', 'p', 'q' and other letters that dig under the baseline will appear to have a larger
  * height than they actually do. Have a look at the tests/text.php test case - the first two
  * columns, 'left and 'center', both look alright, whereas the last column, 'right', appear
  * with a larger space between the first text and the second. This is because the total height
  * is actually smaller by exactly the number of pixels that the 'g' digs under the baseline.
  * Remove the 'g' from the text and they appear correct. 
  *
  * @param string $text The text to get the height of
  * @param bool $force Force the method to calculate the size
  * @return int The height of the text
  */
 function textHeight($text, $force = false)
 {
     if (isset($this->_font['file'])) {
         $angle = 0;
         if (isset($this->_font['angle'])) {
             $angle = $this->_font['angle'];
         }
         $linebreaks = substr_count($text, "\n");
         if ($angle == 0 && $force === false) {
             /*
              * if the angle is 0 simply return the size, due to different
              * heights for example for x-axis labels, making the labels
              * _not_ appear as written on the same baseline
              */
             return $this->_font['size'] + ($this->_font['size'] + 2) * $linebreaks;
         }
         $height = 0;
         $lines = explode("\n", $text);
         foreach ($lines as $line) {
             $bounds = ImageTTFBBox($this->_font['size'], $angle, $this->_font['file'], $line);
             $y0 = min($bounds[1], $bounds[3], $bounds[5], $bounds[7]);
             $y1 = max($bounds[1], $bounds[3], $bounds[5], $bounds[7]);
             $height += abs($y0 - $y1);
         }
         return $height + $linebreaks * 2;
     } else {
         if (isset($this->_font['vertical']) && $this->_font['vertical']) {
             $width = 0;
             $lines = explode("\n", $text);
             foreach ($lines as $line) {
                 $width = max($width, ImageFontWidth($this->_font['font']) * strlen($line));
             }
             return $width;
         } else {
             return ImageFontHeight($this->_font['font']) * (substr_count($text, "\n") + 1);
         }
     }
 }
Example #11
0
 function createCaptchaBackground()
 {
     // Breite eines Zeichens
     $this->image_font_width = ImageFontWidth($this->font_type) + 2;
     // Hoehe eines Zeichens
     $this->image_font_height = ImageFontHeight($this->font_type) + 2;
     // Zufallswerte für hintergrundfarbe
     if ($this->useRandomColors) {
         $this->setBgColor(intval(rand(225, 255)), intval(rand(225, 255)), intval(rand(225, 255)));
     } else {
         $this->setBgColor(225, 225, 225);
     }
     // Hintergrund-Farbe stzen
     $captcha_background_color = ImageColorAllocate($this->image, $this->bgColor['r'], $this->bgColor['g'], $this->bgColor['b']);
     // Flaeche fuellen
     ImageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $captcha_background_color);
     // Zufallsstrings durchloopen
     for ($x = 0; $x < $this->background_intensity; $x++) {
         // Zufallsstring-Farbe
         $random_string_color = ImageColorAllocate($this->image, intval(rand(164, 254)), intval(rand(164, 254)), intval(rand(164, 254)));
         // Zufalls-String generieren
         $random_string = chr(intval(rand(65, 122)));
         // X-Position
         $x_position = intval(rand(0, $this->width - $this->image_font_width * strlen($random_string)));
         // Y-Position
         $y_position = intval(rand(0, $this->height - $this->image_font_height));
         // Zufalls-String
         ImageString($this->image, $this->font_type, $x_position, $y_position, $random_string, $random_string_color);
     }
     if ($this->addagrid) {
         $this->addGrid();
     }
     if ($this->addhorizontallines) {
         $this->addHorizontalLines();
     }
 }
Example #12
0
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
define('ZBX_PAGE_NO_AUTHERIZATION', 1);
require_once "include/config.inc.php";
$page['file'] = 'vtext.php';
$page['type'] = PAGE_TYPE_IMAGE;
include_once "include/page_header.php";
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array("text" => array(T_ZBX_STR, O_OPT, P_SYS, null, null), "font" => array(T_ZBX_INT, O_OPT, null, BETWEEN(1, 5), null));
check_fields($fields);
$text = get_request("text", ' ');
$font = get_request("font", 3);
$width = ImageFontWidth($font) * strlen($text);
$height = ImageFontHeight($font);
$im = imagecreate($height, $width);
$backgroud_color = ImageColorAllocate($im, 255, 255, 255);
$text_color = ImageColorAllocate($im, 0, 0, 0);
ImageStringUp($im, $font, 0, $width - 1, $text, $text_color);
imagecolortransparent($im, $backgroud_color);
ImageOut($im);
ImageDestroy($im);
include_once "include/page_footer.php";
Example #13
0
 /**
  * Actually uploads the file, and act on it according to the set processing class variables
  *
  * This function copies the uploaded file to the given location, eventually performing actions on it.
  * Typically, you can call {@link process} several times for the same file,
  * for instance to create a resized image and a thumbnail of the same file.
  * The original uploaded file remains intact in its temporary location, so you can use {@link process} several times.
  * You will be able to delete the uploaded file with {@link clean} when you have finished all your {@link process} calls.
  *
  * According to the processing class variables set in the calling file, the file can be renamed,
  * and if it is an image, can be resized or converted.
  *
  * When the processing is completed, and the file copied to its new location, the
  * processing class variables will be reset to their default value.
  * This allows you to set new properties, and perform another {@link process} on the same uploaded file
  *
  * It will set {@link processed} (and {@link error} is an error occurred)
  *
  * @access public
  * @param  string $server_path Path location of the uploaded file, with an ending slash
  */
 function process($server_path)
 {
     $this->error = '';
     $this->processed = true;
     if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
         if (substr($server_path, -1, 1) != '\\') {
             $server_path = $server_path . '\\';
         }
     } else {
         if (substr($server_path, -1, 1) != '/') {
             $server_path = $server_path . '/';
         }
     }
     $this->log .= '<b>' . _("process file to") . ' ' . $server_path . '</b><br />';
     // checks file size and mine type
     if ($this->uploaded) {
         if ($this->file_src_size > $this->file_max_size) {
             $this->processed = false;
             $this->error = _(MSG019);
         } else {
             $this->log .= '- ' . _("file size OK") . '<br />';
         }
         // turn dangerous scripts into text files
         if ($this->no_script) {
             if ((substr($this->file_src_mime, 0, 5) == 'text/' || strpos($this->file_src_mime, 'javascript') !== false) && substr($this->file_src_name, -4) != '.txt' || preg_match('/\\.(php|pl|py|cgi|asp)$/i', $this->file_src_name) || empty($this->file_src_name_ext)) {
                 $this->file_src_mime = 'text/plain';
                 $this->log .= '- ' . _("script") . ' ' . $this->file_src_name . ' ' . _("renamed as") . ' ' . $this->file_src_name . '.txt!<br />';
                 $this->file_src_name_ext .= empty($this->file_src_name_ext) ? 'txt' : '.txt';
             }
         }
         // checks MIME type with mime_magic
         if ($this->mime_magic_check && function_exists('mime_content_type')) {
             $detected_mime = mime_content_type($this->file_src_pathname);
             if ($this->file_src_mime != $detected_mime) {
                 $this->log .= '- ' . _("MIME type detected as") . ' ' . $detected_mime . ' ' . _("but given as") . ' ' . $this->file_src_mime . '!<br />';
                 $this->file_src_mime = $detected_mime;
             }
         }
         if ($this->mime_check && empty($this->file_src_mime)) {
             $this->processed = false;
             $this->error = _("MIME type can't be detected!");
         } else {
             if ($this->mime_check && !empty($this->file_src_mime) && !array_key_exists($this->file_src_mime, array_flip($this->allowed))) {
                 $this->processed = false;
                 $this->error = _("Incorrect type of file");
             } else {
                 $this->log .= '- ' . _("file mime OK") . ' : ' . $this->file_src_mime . '<br />';
             }
         }
     } else {
         $this->error = _("File not uploaded. Can't carry on a process");
         $this->processed = false;
     }
     if ($this->processed) {
         $this->file_dst_path = $server_path;
         // repopulate dst variables from src
         $this->file_dst_name = $this->file_src_name;
         $this->file_dst_name_body = $this->file_src_name_body;
         $this->file_dst_name_ext = $this->file_src_name_ext;
         if ($this->file_new_name_body != '') {
             // rename file body
             $this->file_dst_name_body = $this->file_new_name_body;
             $this->log .= '- ' . _("new file name body") . ' : ' . $this->file_new_name_body . '<br />';
         }
         if ($this->file_new_name_ext != '') {
             // rename file ext
             $this->file_dst_name_ext = $this->file_new_name_ext;
             $this->log .= '- ' . _("new file name ext") . ' : ' . $this->file_new_name_ext . '<br />';
         }
         if ($this->file_name_body_add != '') {
             // append a bit to the name
             $this->file_dst_name_body = $this->file_dst_name_body . $this->file_name_body_add;
             $this->log .= '- ' . _("file name body add") . ' : ' . $this->file_name_body_add . '<br />';
         }
         if ($this->file_safe_name) {
             // formats the name
             $this->file_dst_name_body = str_replace(array(' ', '-'), array('_', '_'), $this->file_dst_name_body);
             $this->file_dst_name_body = ereg_replace('[^A-Za-z0-9_]', '', $this->file_dst_name_body);
             $this->log .= '- ' . _("file name safe format") . '<br />';
         }
         $this->log .= '- ' . _("destination variables") . '<br />';
         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_path         : ' . $this->file_dst_path . '<br />';
         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_name_body    : ' . $this->file_dst_name_body . '<br />';
         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_name_ext     : ' . $this->file_dst_name_ext . '<br />';
         // do we do some image manipulation?
         $image_manipulation = $this->image_resize || $this->image_convert != '' || is_numeric($this->image_brightness) || is_numeric($this->image_contrast) || is_numeric($this->image_threshold) || !empty($this->image_tint_color) || !empty($this->image_overlay_color) || !empty($this->image_text) || $this->image_greyscale || $this->image_negative || !empty($this->image_watermark) || is_numeric($this->image_rotate) || is_numeric($this->jpeg_size) || !empty($this->image_flip) || !empty($this->image_crop) || !empty($this->image_border) || $this->image_frame > 0 || $this->image_bevel > 0 || $this->image_reflection_height;
         if ($image_manipulation) {
             if ($this->image_convert == '') {
                 $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : '');
                 $this->log .= '- ' . _("image operation, keep extension") . '<br />';
             } else {
                 $this->file_dst_name = $this->file_dst_name_body . '.' . $this->image_convert;
                 $this->log .= '- ' . _("image operation, change extension for conversion type") . '<br />';
             }
         } else {
             $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : '');
             $this->log .= '- ' . _("no image operation, keep extension") . '<br />';
         }
         if (!$this->file_auto_rename) {
             $this->log .= '- ' . _("no auto_rename if same filename exists") . '<br />';
             $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name;
         } else {
             $this->log .= '- ' . _("checking for auto_rename") . '<br />';
             $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name;
             $body = $this->file_dst_name_body;
             $cpt = 1;
             while (@file_exists($this->file_dst_pathname)) {
                 $this->file_dst_name_body = $body . '_' . $cpt;
                 $this->file_dst_name = $this->file_dst_name_body . (!empty($this->file_dst_name_ext) ? '.' . $this->file_dst_name_ext : '');
                 $cpt++;
                 $this->file_dst_pathname = $this->file_dst_path . $this->file_dst_name;
             }
             if ($cpt > 1) {
                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("auto_rename to") . ' ' . $this->file_dst_name . '<br />';
             }
         }
         $this->log .= '- ' . _("destination file details") . '<br />';
         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_name         : ' . $this->file_dst_name . '<br />';
         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;file_dst_pathname     : ' . $this->file_dst_pathname . '<br />';
         if ($this->file_overwrite) {
             $this->log .= '- ' . _("no overwrite checking") . '<br />';
         } else {
             if (@file_exists($this->file_dst_pathname)) {
                 $this->processed = false;
                 $this->error = $this->file_dst_name . ' ' . _("already exists. Please change the file name");
             } else {
                 $this->log .= '- ' . $this->file_dst_name . ' ' . _("doesn't exist already") . '<br />';
             }
         }
     } else {
         $this->processed = false;
     }
     if (!$this->no_upload_check && !is_uploaded_file($this->file_src_pathname)) {
         $this->processed = false;
         $this->error = _("No correct source file. Can't carry on a process");
     }
     // checks if the destination directory exists, and attempt to create it
     if ($this->processed && !file_exists($this->file_dst_path)) {
         if ($this->dir_auto_create) {
             $this->log .= '- ' . $this->file_dst_path . ' ' . _("doesn't exist. Attempting creation:");
             if (!$this->r_mkdir($this->file_dst_path, $this->dir_chmod)) {
                 $this->log .= ' ' . _("failed") . '<br />';
                 $this->processed = false;
                 $this->error = _("Destination directory can't be created. Can't carry on a process");
             } else {
                 $this->log .= ' ' . _("success") . '<br />';
             }
         } else {
             $this->error = _("Destination directory doesn't exist. Can't carry on a process");
         }
     }
     if ($this->processed && !is_dir($this->file_dst_path)) {
         $this->processed = false;
         $this->error = _("Destination path is not a directory. Can't carry on a process");
     }
     // checks if the destination directory is writeable, and attempt to make it writeable
     $hash = md5($this->file_dst_name_body . rand(1, 1000));
     if ($this->processed && !($f = @fopen($this->file_dst_path . $hash . '.' . $this->file_dst_name_ext, 'a+'))) {
         if ($this->dir_auto_chmod) {
             $this->log .= '- ' . $this->file_dst_path . ' ' . _("is not writeable. Attempting chmod:");
             if (!@chmod($this->file_dst_path, $this->dir_chmod)) {
                 $this->log .= ' ' . _("failed") . '<br />';
                 $this->processed = false;
                 $this->error = _("Destination directory can't be made writeable. Can't carry on a process");
             } else {
                 $this->log .= ' ' . _("success") . '<br />';
                 if (!($f = @fopen($this->file_dst_path . $hash . '.' . $this->file_dst_name_ext, 'a+'))) {
                     // we re-check
                     $this->processed = false;
                     $this->error = _("Destination directory is still not writeable. Can't carry on a process");
                 } else {
                     @fclose($f);
                 }
             }
         } else {
             $this->processed = false;
             $this->error = _("Destination path is not a writeable. Can't carry on a process");
         }
     } else {
         @fclose($f);
         @unlink($this->file_dst_path . $hash . '.' . $this->file_dst_name_ext);
     }
     if ($this->processed) {
         if ($image_manipulation) {
             // we have a writeable destination, but we need to check if we can read the file directly
             // if we can't (open_basedir, etc...), we will copy it with a temporary name
             $has_temp_file = false;
             if ($this->processed && !file_exists($this->file_src_pathname)) {
                 $this->log .= '- ' . _("can't directly access the uploaded file" . '<br />');
                 $this->log .= '    ' . _("attempting creating a temp file:");
                 $hash = md5($this->file_dst_name_body . rand(1, 1000));
                 if (move_uploaded_file($this->file_src_pathname, $this->file_dst_path . $hash . '.' . $this->file_dst_name_ext)) {
                     $this->file_src_pathname = $this->file_dst_path . $hash . '.' . $this->file_dst_name_ext;
                     $this->log .= ' ' . _("file created") . '<br />';
                     $this->log .= '    ' . _("temp file is:") . ' ' . $this->file_src_pathname . '<br />';
                     $has_temp_file = true;
                 } else {
                     $this->log .= ' ' . _("failed") . '<br />';
                     $this->processed = false;
                     $this->error = _("Can't create the temporary file. Can't carry on a process");
                 }
             }
             // checks if the source file is readable
             if ($this->processed && !($f = @fopen($this->file_src_pathname, 'r'))) {
                 $this->processed = false;
                 $this->error = _("Source file is not readable. Can't carry on a process");
             } else {
                 @fclose($f);
             }
             // we now do all the image manipulations
             $this->log .= '- ' . _("image resizing or conversion wanted") . '<br />';
             if ($this->gd_version()) {
                 switch ($this->file_src_mime) {
                     case 'image/pjpeg':
                     case 'image/jpeg':
                     case 'image/jpg':
                         if (!function_exists('imagecreatefromjpeg')) {
                             $this->processed = false;
                             $this->error = _("No create from JPEG support");
                         } else {
                             $image_src = @imagecreatefromjpeg($this->file_src_pathname);
                             if (!$image_src) {
                                 $this->processed = false;
                                 $this->error = _("Error in creating JPEG image from source");
                             } else {
                                 $this->log .= '- ' . _("source image is JPEG") . '<br />';
                             }
                         }
                         break;
                     case 'image/x-png':
                     case 'image/png':
                         if (!function_exists('imagecreatefrompng')) {
                             $this->processed = false;
                             $this->error = _("No create from PNG support");
                         } else {
                             $image_src = @imagecreatefrompng($this->file_src_pathname);
                             if (!$image_src) {
                                 $this->processed = false;
                                 $this->error = _("Error in creating PNG image from source");
                             } else {
                                 $this->log .= '- ' . _("source image is PNG") . '<br />';
                             }
                         }
                         break;
                     case 'image/gif':
                         if (!function_exists('imagecreatefromgif')) {
                             $this->processed = false;
                             $this->error = _("Error in creating GIF image from source");
                         } else {
                             $image_src = @imagecreatefromgif($this->file_src_pathname);
                             if (!$image_src) {
                                 $this->processed = false;
                                 $this->error = _("No GIF read support");
                             } else {
                                 $this->log .= '- ' . _("source image is GIF") . '<br />';
                             }
                         }
                         break;
                     default:
                         $this->processed = false;
                         $this->error = _(MSG012);
                 }
             } else {
                 $this->processed = false;
                 $this->error = _("GD doesn't seem to be present");
             }
             if ($this->processed && $image_src) {
                 $this->image_src_x = imagesx($image_src);
                 $this->image_src_y = imagesy($image_src);
                 $this->image_dst_x = $this->image_src_x;
                 $this->image_dst_y = $this->image_src_y;
                 $gd_version = $this->gd_version();
                 $ratio_crop = null;
                 if ($this->image_resize) {
                     $this->log .= '- ' . _("resizing...") . '<br />';
                     if ($this->image_ratio_x) {
                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("calculate x size") . '<br />';
                         $this->image_dst_x = round($this->image_src_x * $this->image_y / $this->image_src_y);
                         $this->image_dst_y = $this->image_y;
                     } else {
                         if ($this->image_ratio_y) {
                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("calculate y size") . '<br />';
                             $this->image_dst_x = $this->image_x;
                             $this->image_dst_y = round($this->image_src_y * $this->image_x / $this->image_src_x);
                         } else {
                             if ($this->image_ratio || $this->image_ratio_crop || $this->image_ratio_no_zoom_in || $this->image_ratio_no_zoom_out) {
                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("check x/y sizes") . '<br />';
                                 if (!$this->image_ratio_no_zoom_in && !$this->image_ratio_no_zoom_out || $this->image_ratio_no_zoom_in && ($this->image_src_x > $this->image_x || $this->image_src_y > $this->image_y) || $this->image_ratio_no_zoom_out && $this->image_src_x < $this->image_x && $this->image_src_y < $this->image_y) {
                                     $this->image_dst_x = $this->image_x;
                                     $this->image_dst_y = $this->image_y;
                                     if ($this->image_ratio_crop) {
                                         if (!is_string($this->image_ratio_crop)) {
                                             $this->image_ratio_crop = '';
                                         }
                                         $this->image_ratio_crop = strtolower($this->image_ratio_crop);
                                         if ($this->image_src_x / $this->image_x > $this->image_src_y / $this->image_y) {
                                             $this->image_dst_y = $this->image_y;
                                             $this->image_dst_x = intval($this->image_src_x * ($this->image_y / $this->image_src_y));
                                             $ratio_crop = array();
                                             $ratio_crop['x'] = $this->image_dst_x - $this->image_x;
                                             if (strpos($this->image_ratio_crop, 'l') !== false) {
                                                 $ratio_crop['l'] = 0;
                                                 $ratio_crop['r'] = $ratio_crop['x'];
                                             } else {
                                                 if (strpos($this->image_ratio_crop, 'r') !== false) {
                                                     $ratio_crop['l'] = $ratio_crop['x'];
                                                     $ratio_crop['r'] = 0;
                                                 } else {
                                                     $ratio_crop['l'] = round($ratio_crop['x'] / 2);
                                                     $ratio_crop['r'] = $ratio_crop['x'] - $ratio_crop['l'];
                                                 }
                                             }
                                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("ratio_crop_x") . '         : ' . $ratio_crop['x'] . ' (' . $ratio_crop['l'] . ';' . $ratio_crop['r'] . ')<br />';
                                             if (is_null($this->image_crop)) {
                                                 $this->image_crop = array(0, 0, 0, 0);
                                             }
                                         } else {
                                             $this->image_dst_x = $this->image_x;
                                             $this->image_dst_y = intval($this->image_src_y * ($this->image_x / $this->image_src_x));
                                             $ratio_crop = array();
                                             $ratio_crop['y'] = $this->image_dst_y - $this->image_y;
                                             if (strpos($this->image_ratio_crop, 't') !== false) {
                                                 $ratio_crop['t'] = 0;
                                                 $ratio_crop['b'] = $ratio_crop['y'];
                                             } else {
                                                 if (strpos($this->image_ratio_crop, 'b') !== false) {
                                                     $ratio_crop['t'] = $ratio_crop['y'];
                                                     $ratio_crop['b'] = 0;
                                                 } else {
                                                     $ratio_crop['t'] = round($ratio_crop['y'] / 2);
                                                     $ratio_crop['b'] = $ratio_crop['y'] - $ratio_crop['t'];
                                                 }
                                             }
                                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("ratio_crop_y") . '         : ' . $ratio_crop['y'] . ' (' . $ratio_crop['t'] . ';' . $ratio_crop['b'] . ')<br />';
                                             if (is_null($this->image_crop)) {
                                                 $this->image_crop = array(0, 0, 0, 0);
                                             }
                                         }
                                     } else {
                                         if ($this->image_src_x / $this->image_x > $this->image_src_y / $this->image_y) {
                                             $this->image_dst_x = $this->image_x;
                                             $this->image_dst_y = intval($this->image_src_y * ($this->image_x / $this->image_src_x));
                                         } else {
                                             $this->image_dst_y = $this->image_y;
                                             $this->image_dst_x = intval($this->image_src_x * ($this->image_y / $this->image_src_y));
                                         }
                                     }
                                 } else {
                                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("doesn't calculate x/y sizes") . '<br />';
                                     $this->image_dst_x = $this->image_src_x;
                                     $this->image_dst_y = $this->image_src_y;
                                 }
                             } else {
                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("use plain sizes") . '<br />';
                                 $this->image_dst_x = $this->image_x;
                                 $this->image_dst_y = $this->image_y;
                             }
                         }
                     }
                     if ($this->preserve_transparency && $this->file_src_mime != 'image/gif' && $this->file_src_mime != 'image/png') {
                         $this->preserve_transparency = false;
                     }
                     if ($gd_version >= 2 && !$this->preserve_transparency) {
                         $image_dst = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     } else {
                         $image_dst = imagecreate($this->image_dst_x, $this->image_dst_y);
                     }
                     if ($this->preserve_transparency) {
                         $this->log .= '- ' . _("preserve transparency") . '<br />';
                         $transparent_color = imagecolortransparent($image_src);
                         imagepalettecopy($image_dst, $image_src);
                         imagefill($image_dst, 0, 0, $transparent_color);
                         imagecolortransparent($image_dst, $transparent_color);
                     }
                     if ($gd_version >= 2 && !$this->preserve_transparency) {
                         $res = imagecopyresampled($image_dst, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y);
                     } else {
                         $res = imagecopyresized($image_dst, $image_src, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_src_x, $this->image_src_y);
                     }
                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("resized image object created") . '<br />';
                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_src_x y        : ' . $this->image_src_x . ' x ' . $this->image_src_y . '<br />';
                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;image_dst_x y        : ' . $this->image_dst_x . ' x ' . $this->image_dst_y . '<br />';
                 } else {
                     // we only convert, so we link the dst image to the src image
                     $image_dst =& $image_src;
                 }
                 // we have to set image_convert if it is not already
                 if (empty($this->image_convert)) {
                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("setting destination file type to") . ' ' . $this->file_src_name_ext . '<br />';
                     $this->image_convert = $this->file_src_name_ext;
                 }
                 // crop imag (and also crops if image_ratio_crop is used)
                 if ($gd_version >= 2 && (!empty($this->image_crop) || !is_null($ratio_crop))) {
                     if (is_array($this->image_crop)) {
                         $vars = $this->image_crop;
                     } else {
                         $vars = explode(' ', $this->image_crop);
                     }
                     if (sizeof($vars) == 4) {
                         $ct = $vars[0];
                         $cr = $vars[1];
                         $cb = $vars[2];
                         $cl = $vars[3];
                     } else {
                         if (sizeof($vars) == 2) {
                             $ct = $vars[0];
                             $cr = $vars[1];
                             $cb = $vars[0];
                             $cl = $vars[1];
                         } else {
                             $ct = $vars[0];
                             $cr = $vars[0];
                             $cb = $vars[0];
                             $cl = $vars[0];
                         }
                     }
                     if (strpos($ct, '%') > 0) {
                         $ct = $this->image_dst_y * (str_replace('%', '', $ct) / 100);
                     }
                     if (strpos($cr, '%') > 0) {
                         $cr = $this->image_dst_x * (str_replace('%', '', $cr) / 100);
                     }
                     if (strpos($cb, '%') > 0) {
                         $cb = $this->image_dst_y * (str_replace('%', '', $cb) / 100);
                     }
                     if (strpos($cl, '%') > 0) {
                         $cl = $this->image_dst_x * (str_replace('%', '', $cl) / 100);
                     }
                     if (strpos($ct, 'px') > 0) {
                         $ct = str_replace('px', '', $ct);
                     }
                     if (strpos($cr, 'px') > 0) {
                         $cr = str_replace('px', '', $cr);
                     }
                     if (strpos($cb, 'px') > 0) {
                         $cb = str_replace('px', '', $cb);
                     }
                     if (strpos($cl, 'px') > 0) {
                         $cl = str_replace('px', '', $cl);
                     }
                     $ct = (int) $ct;
                     $cr = (int) $cr;
                     $cb = (int) $cb;
                     $cl = (int) $cl;
                     // we adjust the cropping if we use image_ratio_crop
                     if (!is_null($ratio_crop)) {
                         if (array_key_exists('t', $ratio_crop)) {
                             $ct += $ratio_crop['t'];
                         }
                         if (array_key_exists('r', $ratio_crop)) {
                             $cr += $ratio_crop['r'];
                         }
                         if (array_key_exists('b', $ratio_crop)) {
                             $cb += $ratio_crop['b'];
                         }
                         if (array_key_exists('l', $ratio_crop)) {
                             $cl += $ratio_crop['l'];
                         }
                     }
                     $this->log .= '- ' . _("crop image") . ' : ' . $ct . ' ' . $cr . ' ' . $cb . ' ' . $cl . ' <br />';
                     $this->image_dst_x = $this->image_dst_x - $cl - $cr;
                     $this->image_dst_y = $this->image_dst_y - $ct - $cb;
                     if ($this->image_dst_x < 1) {
                         $this->image_dst_x = 1;
                     }
                     if ($this->image_dst_y < 1) {
                         $this->image_dst_y = 1;
                     }
                     $tmp = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     imagecopy($tmp, $image_dst, 0, 0, $cl, $ct, $this->image_dst_x, $this->image_dst_y);
                     // we transfert tmp into image_dst
                     imagedestroy($image_dst);
                     $image_dst = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     imagecopy($image_dst, $tmp, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
                     imagedestroy($tmp);
                 }
                 // flip image
                 if ($gd_version >= 2 && !empty($this->image_flip)) {
                     $this->image_flip = strtolower($this->image_flip);
                     $this->log .= '- ' . _("flip image") . ' : ' . $this->image_flip . '<br />';
                     $tmp = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     for ($x = 0; $x < $this->image_dst_x; $x++) {
                         for ($y = 0; $y < $this->image_dst_y; $y++) {
                             if (strpos($this->image_flip, 'v') !== false) {
                                 imagecopy($tmp, $image_dst, $this->image_dst_x - $x - 1, $y, $x, $y, 1, 1);
                             } else {
                                 imagecopy($tmp, $image_dst, $x, $this->image_dst_y - $y - 1, $x, $y, 1, 1);
                             }
                         }
                     }
                     // we transfert tmp into image_dst
                     imagedestroy($image_dst);
                     $image_dst = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     imagecopy($image_dst, $tmp, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
                     imagedestroy($tmp);
                 }
                 // rotate image
                 if ($gd_version >= 2 && is_numeric($this->image_rotate)) {
                     if (!in_array($this->image_rotate, array(0, 90, 180, 270))) {
                         $this->image_rotate = 0;
                     }
                     if ($this->image_rotate != 0) {
                         if ($this->image_rotate == 90 || $this->image_rotate == 270) {
                             $tmp = imagecreatetruecolor($this->image_dst_y, $this->image_dst_x);
                         } else {
                             $tmp = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                         }
                         $this->log .= '- ' . _("rotate image") . ' : ' . $this->image_rotate . '<br />';
                         for ($x = 0; $x < $this->image_dst_x; $x++) {
                             for ($y = 0; $y < $this->image_dst_y; $y++) {
                                 if ($this->image_rotate == 90) {
                                     imagecopy($tmp, $image_dst, $y, $x, $x, $this->image_dst_y - $y - 1, 1, 1);
                                 } else {
                                     if ($this->image_rotate == 180) {
                                         imagecopy($tmp, $image_dst, $x, $y, $this->image_dst_x - $x - 1, $this->image_dst_y - $y - 1, 1, 1);
                                     } else {
                                         if ($this->image_rotate == 270) {
                                             imagecopy($tmp, $image_dst, $y, $x, $this->image_dst_x - $x - 1, $y, 1, 1);
                                         } else {
                                             imagecopy($tmp, $image_dst, $x, $y, $x, $y, 1, 1);
                                         }
                                     }
                                 }
                             }
                         }
                         if ($this->image_rotate == 90 || $this->image_rotate == 270) {
                             $t = $this->image_dst_y;
                             $this->image_dst_y = $this->image_dst_x;
                             $this->image_dst_x = $t;
                         }
                         // we transfert tmp into image_dst
                         imagedestroy($image_dst);
                         $image_dst = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                         imagecopy($image_dst, $tmp, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
                         imagedestroy($tmp);
                     }
                 }
                 // add color overlay
                 if ($gd_version >= 2 && (is_numeric($this->image_overlay_percent) && !empty($this->image_overlay_color))) {
                     $this->log .= '- ' . _("apply color overlay") . '<br />';
                     sscanf($this->image_overlay_color, "#%2x%2x%2x", $red, $green, $blue);
                     $filter = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     $color = imagecolorallocate($filter, $red, $green, $blue);
                     imagefilledrectangle($filter, 0, 0, $this->image_dst_x, $this->image_dst_y, $color);
                     imagecopymerge($image_dst, $filter, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y, $this->image_overlay_percent);
                     imagedestroy($filter);
                 }
                 // add brightness, contrast and tint, turns to greyscale and inverts colors
                 if ($gd_version >= 2 && ($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))) {
                     $this->log .= '- ' . _("apply tint, light, contrast correction, negative, greyscale and threshold") . '<br />';
                     if (!empty($this->image_tint_color)) {
                         sscanf($this->image_tint_color, "#%2x%2x%2x", $red, $green, $blue);
                     }
                     $background = imagecolorallocatealpha($image_dst, 255, 255, 255, 0);
                     imagefill($image_dst, 0, 0, $background);
                     imagealphablending($image_dst, TRUE);
                     for ($y = 0; $y < $this->image_dst_y; $y++) {
                         for ($x = 0; $x < $this->image_dst_x; $x++) {
                             if ($this->image_greyscale) {
                                 $rgb = imagecolorat($image_dst, $x, $y);
                                 $pixel = imagecolorsforindex($image_dst, $rgb);
                                 $r = $g = $b = round(0.2125 * $pixel['red'] + 0.7154 * $pixel['green'] + 0.0721 * $pixel['blue']);
                                 $a = $pixel['alpha'];
                                 $pixelcolor = imagecolorallocatealpha($image_dst, $r, $g, $b, $a);
                                 imagesetpixel($image_dst, $x, $y, $pixelcolor);
                             }
                             if (is_numeric($this->image_threshold)) {
                                 $rgb = imagecolorat($image_dst, $x, $y);
                                 $pixel = imagecolorsforindex($image_dst, $rgb);
                                 $c = round($pixel['red'] + $pixel['green'] + $pixel['blue']) / 3 - 127;
                                 $r = $g = $b = $c > $this->image_threshold ? 255 : 0;
                                 $a = $pixel['alpha'];
                                 $pixelcolor = imagecolorallocatealpha($image_dst, $r, $g, $b, $a);
                                 imagesetpixel($image_dst, $x, $y, $pixelcolor);
                             }
                             if (is_numeric($this->image_brightness)) {
                                 $rgb = imagecolorat($image_dst, $x, $y);
                                 $pixel = imagecolorsforindex($image_dst, $rgb);
                                 $r = max(min(round($pixel['red'] + $this->image_brightness * 2), 255), 0);
                                 $g = max(min(round($pixel['green'] + $this->image_brightness * 2), 255), 0);
                                 $b = max(min(round($pixel['blue'] + $this->image_brightness * 2), 255), 0);
                                 $a = $pixel['alpha'];
                                 $pixelcolor = imagecolorallocatealpha($image_dst, $r, $g, $b, $a);
                                 imagesetpixel($image_dst, $x, $y, $pixelcolor);
                             }
                             if (is_numeric($this->image_contrast)) {
                                 $rgb = imagecolorat($image_dst, $x, $y);
                                 $pixel = imagecolorsforindex($image_dst, $rgb);
                                 $r = max(min(round(($this->image_contrast + 128) * $pixel['red'] / 128), 255), 0);
                                 $g = max(min(round(($this->image_contrast + 128) * $pixel['green'] / 128), 255), 0);
                                 $b = max(min(round(($this->image_contrast + 128) * $pixel['blue'] / 128), 255), 0);
                                 $a = $pixel['alpha'];
                                 $pixelcolor = imagecolorallocatealpha($image_dst, $r, $g, $b, $a);
                                 imagesetpixel($image_dst, $x, $y, $pixelcolor);
                             }
                             if (!empty($this->image_tint_color)) {
                                 $rgb = imagecolorat($image_dst, $x, $y);
                                 $pixel = imagecolorsforindex($image_dst, $rgb);
                                 $r = min(round($red * $pixel['red'] / 169), 255);
                                 $g = min(round($green * $pixel['green'] / 169), 255);
                                 $b = min(round($blue * $pixel['blue'] / 169), 255);
                                 $a = $pixel['alpha'];
                                 $pixelcolor = imagecolorallocatealpha($image_dst, $r, $g, $b, $a);
                                 imagesetpixel($image_dst, $x, $y, $pixelcolor);
                             }
                             if (!empty($this->image_negative)) {
                                 $rgb = imagecolorat($image_dst, $x, $y);
                                 $pixel = imagecolorsforindex($image_dst, $rgb);
                                 $r = round(255 - $pixel['red']);
                                 $g = round(255 - $pixel['green']);
                                 $b = round(255 - $pixel['blue']);
                                 $a = $pixel['alpha'];
                                 $pixelcolor = imagecolorallocatealpha($image_dst, $r, $g, $b, $a);
                                 imagesetpixel($image_dst, $x, $y, $pixelcolor);
                             }
                         }
                     }
                 }
                 // adds a border
                 if ($gd_version >= 2 && !empty($this->image_border)) {
                     if (is_array($this->image_border)) {
                         $vars = $this->image_border;
                         $this->log .= '- ' . _("add border") . ' : ' . implode(' ', $this->image_border) . '<br />';
                     } else {
                         $this->log .= '- ' . _("add border") . ' : ' . $this->image_border . '<br />';
                         $vars = explode(' ', $this->image_border);
                     }
                     if (sizeof($vars) == 4) {
                         $ct = $vars[0];
                         $cr = $vars[1];
                         $cb = $vars[2];
                         $cl = $vars[3];
                     } else {
                         if (sizeof($vars) == 2) {
                             $ct = $vars[0];
                             $cr = $vars[1];
                             $cb = $vars[0];
                             $cl = $vars[1];
                         } else {
                             $ct = $vars[0];
                             $cr = $vars[0];
                             $cb = $vars[0];
                             $cl = $vars[0];
                         }
                     }
                     if (strpos($ct, '%') > 0) {
                         $ct = $this->image_dst_y * (str_replace('%', '', $ct) / 100);
                     }
                     if (strpos($cr, '%') > 0) {
                         $cr = $this->image_dst_x * (str_replace('%', '', $cr) / 100);
                     }
                     if (strpos($cb, '%') > 0) {
                         $cb = $this->image_dst_y * (str_replace('%', '', $cb) / 100);
                     }
                     if (strpos($cl, '%') > 0) {
                         $cl = $this->image_dst_x * (str_replace('%', '', $cl) / 100);
                     }
                     if (strpos($ct, 'px') > 0) {
                         $ct = str_replace('px', '', $ct);
                     }
                     if (strpos($cr, 'px') > 0) {
                         $cr = str_replace('px', '', $cr);
                     }
                     if (strpos($cb, 'px') > 0) {
                         $cb = str_replace('px', '', $cb);
                     }
                     if (strpos($cl, 'px') > 0) {
                         $cl = str_replace('px', '', $cl);
                     }
                     $ct = (int) $ct;
                     $cr = (int) $cr;
                     $cb = (int) $cb;
                     $cl = (int) $cl;
                     $this->image_dst_x = $this->image_dst_x + $cl + $cr;
                     $this->image_dst_y = $this->image_dst_y + $ct + $cb;
                     if (!empty($this->image_border_color)) {
                         sscanf($this->image_border_color, "#%2x%2x%2x", $red, $green, $blue);
                     }
                     $tmp = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     $background = imagecolorallocatealpha($tmp, $red, $green, $blue, 0);
                     imagefill($tmp, 0, 0, $background);
                     imagecopy($tmp, $image_dst, $cl, $ct, 0, 0, $this->image_dst_x - $cr - $cl, $this->image_dst_y - $cb - $ct);
                     // we transfert tmp into image_dst
                     imagedestroy($image_dst);
                     $image_dst = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     imagecopy($image_dst, $tmp, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
                     imagedestroy($tmp);
                 }
                 // add frame border
                 if (is_numeric($this->image_frame)) {
                     if (is_array($this->image_frame_colors)) {
                         $vars = $this->image_frame_colors;
                         $this->log .= '- ' . _("add frame") . ' : ' . implode(' ', $this->image_frame_colors) . '<br />';
                     } else {
                         $this->log .= '- ' . _("add frame") . ' : ' . $this->image_frame_colors . '<br />';
                         $vars = explode(' ', $this->image_frame_colors);
                     }
                     $nb = sizeof($vars);
                     $this->image_dst_x = $this->image_dst_x + $nb * 2;
                     $this->image_dst_y = $this->image_dst_y + $nb * 2;
                     $tmp = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     imagecopy($tmp, $image_dst, $nb, $nb, 0, 0, $this->image_dst_x - $nb * 2, $this->image_dst_y - $nb * 2);
                     for ($i = 0; $i < $nb; $i++) {
                         sscanf($vars[$i], "#%2x%2x%2x", $red, $green, $blue);
                         $c = imagecolorallocate($tmp, $red, $green, $blue);
                         if ($this->image_frame == 1) {
                             imageline($tmp, $i, $i, $this->image_dst_x - $i - 1, $i, $c);
                             imageline($tmp, $this->image_dst_x - $i - 1, $this->image_dst_y - $i - 1, $this->image_dst_x - $i - 1, $i, $c);
                             imageline($tmp, $this->image_dst_x - $i - 1, $this->image_dst_y - $i - 1, $i, $this->image_dst_y - $i - 1, $c);
                             imageline($tmp, $i, $i, $i, $this->image_dst_y - $i - 1, $c);
                         } else {
                             imageline($tmp, $i, $i, $this->image_dst_x - $i - 1, $i, $c);
                             imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $this->image_dst_x - $nb + $i, $nb - $i, $c);
                             imageline($tmp, $this->image_dst_x - $nb + $i, $this->image_dst_y - $nb + $i, $nb - $i, $this->image_dst_y - $nb + $i, $c);
                             imageline($tmp, $i, $i, $i, $this->image_dst_y - $i - 1, $c);
                         }
                     }
                     // we transfert tmp into image_dst
                     imagedestroy($image_dst);
                     $image_dst = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     imagecopy($image_dst, $tmp, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
                     imagedestroy($tmp);
                 }
                 // add bevel border
                 if ($this->image_bevel > 0) {
                     if (empty($this->image_bevel_color1)) {
                         $this->image_bevel_color1 = '#FFFFFF';
                     }
                     if (empty($this->image_bevel_color2)) {
                         $this->image_bevel_color2 = '#000000';
                     }
                     sscanf($this->image_bevel_color1, "#%2x%2x%2x", $red1, $green1, $blue1);
                     sscanf($this->image_bevel_color2, "#%2x%2x%2x", $red2, $green2, $blue2);
                     imagealphablending($image_dst, true);
                     for ($i = 0; $i < $this->image_bevel; $i++) {
                         $alpha = round($i / $this->image_bevel * 127);
                         $c1 = imagecolorallocatealpha($image_dst, $red1, $green1, $blue1, $alpha);
                         $c2 = imagecolorallocatealpha($image_dst, $red2, $green2, $blue2, $alpha);
                         imageline($image_dst, $i, $i, $this->image_dst_x - $i - 1, $i, $c1);
                         imageline($image_dst, $this->image_dst_x - $i - 1, $this->image_dst_y - $i, $this->image_dst_x - $i - 1, $i, $c2);
                         imageline($image_dst, $this->image_dst_x - $i - 1, $this->image_dst_y - $i - 1, $i, $this->image_dst_y - $i - 1, $c2);
                         imageline($image_dst, $i, $i, $i, $this->image_dst_y - $i - 1, $c1);
                     }
                 }
                 // add watermark image
                 if ($this->image_watermark != '' && file_exists($this->image_watermark)) {
                     $this->log .= '- ' . _("add watermark") . '<br />';
                     $this->image_watermark_position = strtolower($this->image_watermark_position);
                     $watermark_info = getimagesize($this->image_watermark);
                     $watermark_type = array_key_exists(2, $watermark_info) ? $watermark_info[2] : NULL;
                     // 1 = GIF, 2 = JPG, 3 = PNG
                     $watermark_checked = false;
                     if ($watermark_type == 1) {
                         if (!function_exists('imagecreatefromgif')) {
                             $this->error = _("No create from GIF support, can't read watermark");
                         } else {
                             $filter = @imagecreatefromgif($this->image_watermark);
                             if (!$filter) {
                                 $this->error = _("No GIF read support, can't create watermark");
                             } else {
                                 $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("watermark source image is GIF") . '<br />';
                                 $watermark_checked = true;
                             }
                         }
                     } else {
                         if ($watermark_type == 2) {
                             if (!function_exists('imagecreatefromjpeg')) {
                                 $this->error = _("No create from JPG support, can't read watermark");
                             } else {
                                 $filter = @imagecreatefromjpeg($this->image_watermark);
                                 if (!$filter) {
                                     $this->error = _("No JPG read support, can't create watermark");
                                 } else {
                                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("watermark source image is JPG") . '<br />';
                                     $watermark_checked = true;
                                 }
                             }
                         } else {
                             if ($watermark_type == 3) {
                                 if (!function_exists('imagecreatefrompng')) {
                                     $this->error = _("No create from PNG support, can't read watermark");
                                 } else {
                                     $filter = @imagecreatefrompng($this->image_watermark);
                                     if (!$filter) {
                                         $this->error = _("No PNG read support, can't create watermark");
                                     } else {
                                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("watermark source image is PNG") . '<br />';
                                         $watermark_checked = true;
                                     }
                                 }
                             }
                         }
                     }
                     if ($watermark_checked) {
                         $watermark_width = imagesx($filter);
                         $watermark_height = imagesy($filter);
                         $watermark_x = 0;
                         $watermark_y = 0;
                         if (is_numeric($this->image_watermark_x)) {
                             if ($this->image_watermark_x < 0) {
                                 $watermark_x = $this->image_dst_x - $watermark_width + $this->image_watermark_x;
                             } else {
                                 $watermark_x = $this->image_watermark_x;
                             }
                         } else {
                             if (strpos($this->image_watermark_position, 'r') !== false) {
                                 $watermark_x = $this->image_dst_x - $watermark_width;
                             } else {
                                 if (strpos($this->image_watermark_position, 'l') !== false) {
                                     $watermark_x = 0;
                                 } else {
                                     $watermark_x = ($this->image_dst_x - $watermark_width) / 2;
                                 }
                             }
                         }
                         if (is_numeric($this->image_watermark_y)) {
                             if ($this->image_watermark_y < 0) {
                                 $watermark_y = $this->image_dst_y - $watermark_height + $this->image_watermark_y;
                             } else {
                                 $watermark_y = $this->image_watermark_y;
                             }
                         } else {
                             if (strpos($this->image_watermark_position, 'b') !== false) {
                                 $watermark_y = $this->image_dst_y - $watermark_height;
                             } else {
                                 if (strpos($this->image_watermark_position, 't') !== false) {
                                     $watermark_y = 0;
                                 } else {
                                     $watermark_y = ($this->image_dst_y - $watermark_height) / 2;
                                 }
                             }
                         }
                         imagecopyresampled($image_dst, $filter, $watermark_x, $watermark_y, 0, 0, $watermark_width, $watermark_height, $watermark_width, $watermark_height);
                     } else {
                         $this->error = _("Watermark image is of unknown type");
                     }
                 }
                 // add text
                 if (!empty($this->image_text)) {
                     $this->log .= '- ' . _("add text") . '<br />';
                     if (!is_numeric($this->image_text_padding)) {
                         $this->image_text_padding = 0;
                     }
                     if (!is_numeric($this->image_text_line_spacing)) {
                         $this->image_text_line_spacing = 0;
                     }
                     if (!is_numeric($this->image_text_padding_x)) {
                         $this->image_text_padding_x = $this->image_text_padding;
                     }
                     if (!is_numeric($this->image_text_padding_y)) {
                         $this->image_text_padding_y = $this->image_text_padding;
                     }
                     $this->image_text_position = strtolower($this->image_text_position);
                     $this->image_text_direction = strtolower($this->image_text_direction);
                     $this->image_text_alignment = strtolower($this->image_text_alignment);
                     // if the font is a string, we assume that we might want to load a font
                     if (!is_numeric($this->image_text_font) && strlen($this->image_text_font) > 4 && substr(strtolower($this->image_text_font), -4) == '.gdf') {
                         $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("try to load font") . ' ' . $this->image_text_font . '... ';
                         if ($this->image_text_font = @imageloadfont($this->image_text_font)) {
                             $this->log .= _("success") . '<br />';
                         } else {
                             $this->log .= _("error") . '<br />';
                             $this->image_text_font = 5;
                         }
                     }
                     $text = explode("\n", $this->image_text);
                     $char_width = ImageFontWidth($this->image_text_font);
                     $char_height = ImageFontHeight($this->image_text_font);
                     $text_height = 0;
                     $text_width = 0;
                     $line_height = 0;
                     $line_width = 0;
                     foreach ($text as $k => $v) {
                         if ($this->image_text_direction == 'v') {
                             $h = $char_width * strlen($v);
                             if ($h > $text_height) {
                                 $text_height = $h;
                             }
                             $line_width = $char_height;
                             $text_width += $line_width + ($k < sizeof($text) - 1 ? $this->image_text_line_spacing : 0);
                         } else {
                             $w = $char_width * strlen($v);
                             if ($w > $text_width) {
                                 $text_width = $w;
                             }
                             $line_height = $char_height;
                             $text_height += $line_height + ($k < sizeof($text) - 1 ? $this->image_text_line_spacing : 0);
                         }
                     }
                     $text_width += 2 * $this->image_text_padding_x;
                     $text_height += 2 * $this->image_text_padding_y;
                     $text_x = 0;
                     $text_y = 0;
                     if (is_numeric($this->image_text_x)) {
                         if ($this->image_text_x < 0) {
                             $text_x = $this->image_dst_x - $text_width + $this->image_text_x;
                         } else {
                             $text_x = $this->image_text_x;
                         }
                     } else {
                         if (strpos($this->image_text_position, 'r') !== false) {
                             $text_x = $this->image_dst_x - $text_width;
                         } else {
                             if (strpos($this->image_text_position, 'l') !== false) {
                                 $text_x = 0;
                             } else {
                                 $text_x = ($this->image_dst_x - $text_width) / 2;
                             }
                         }
                     }
                     if (is_numeric($this->image_text_y)) {
                         if ($this->image_text_y < 0) {
                             $text_y = $this->image_dst_y - $text_height + $this->image_text_y;
                         } else {
                             $text_y = $this->image_text_y;
                         }
                     } else {
                         if (strpos($this->image_text_position, 'b') !== false) {
                             $text_y = $this->image_dst_y - $text_height;
                         } else {
                             if (strpos($this->image_text_position, 't') !== false) {
                                 $text_y = 0;
                             } else {
                                 $text_y = ($this->image_dst_y - $text_height) / 2;
                             }
                         }
                     }
                     // add a background, maybe transparent
                     if (!empty($this->image_text_background)) {
                         sscanf($this->image_text_background, "#%2x%2x%2x", $red, $green, $blue);
                         if ($gd_version >= 2 && is_numeric($this->image_text_background_percent) && $this->image_text_background_percent >= 0 && $this->image_text_background_percent <= 100) {
                             $filter = imagecreatetruecolor($text_width, $text_height);
                             $background_color = imagecolorallocate($filter, $red, $green, $blue);
                             imagefilledrectangle($filter, 0, 0, $text_width, $text_height, $background_color);
                             imagecopymerge($image_dst, $filter, $text_x, $text_y, 0, 0, $text_width, $text_height, $this->image_text_background_percent);
                             imagedestroy($filter);
                         } else {
                             $background_color = imageColorAllocate($image_dst, $red, $green, $blue);
                             imagefilledrectangle($image_dst, $text_x, $text_y, $text_x + $text_width, $text_y + $text_height, $background_color);
                         }
                     }
                     $text_x += $this->image_text_padding_x;
                     $text_y += $this->image_text_padding_y;
                     $t_width = $text_width - 2 * $this->image_text_padding_x;
                     $t_height = $text_height - 2 * $this->image_text_padding_y;
                     sscanf($this->image_text_color, "#%2x%2x%2x", $red, $green, $blue);
                     // add the text, maybe transparent
                     if ($gd_version >= 2 && is_numeric($this->image_text_percent) && $this->image_text_percent >= 0 && $this->image_text_percent <= 100) {
                         if ($t_width < 0) {
                             $t_width = 0;
                         }
                         if ($t_height < 0) {
                             $t_height = 0;
                         }
                         $filter = imagecreatetruecolor($t_width, $t_height);
                         $color = imagecolorallocate($filter, 0, 0, $blue == 0 ? 255 : 0);
                         imagefill($filter, 0, 0, $color);
                         $text_color = imagecolorallocate($filter, $red, $green, $blue);
                         imagecolortransparent($filter, $color);
                         foreach ($text as $k => $v) {
                             if ($this->image_text_direction == 'v') {
                                 imagestringup($filter, $this->image_text_font, $k * ($line_width + ($k > 0 && $k < sizeof($text) ? $this->image_text_line_spacing : 0)), $text_height - 2 * $this->image_text_padding_y - ($this->image_text_alignment == 'l' ? 0 : ($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2)), $v, $text_color);
                             } else {
                                 imagestring($filter, $this->image_text_font, $this->image_text_alignment == 'l' ? 0 : ($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2), $k * ($line_height + ($k > 0 && $k < sizeof($text) ? $this->image_text_line_spacing : 0)), $v, $text_color);
                             }
                         }
                         imagecopymerge($image_dst, $filter, $text_x, $text_y, 0, 0, $t_width, $t_height, $this->image_text_percent);
                         imagedestroy($filter);
                     } else {
                         $text_color = imageColorAllocate($image_dst, $red, $green, $blue);
                         foreach ($text as $k => $v) {
                             if ($this->image_text_direction == 'v') {
                                 imagestringup($image_dst, $this->image_text_font, $text_x + $k * ($line_width + ($k > 0 && $k < sizeof($text) ? $this->image_text_line_spacing : 0)), $text_y + $text_height - 2 * $this->image_text_padding_y - ($this->image_text_alignment == 'l' ? 0 : ($t_height - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2)), $v, $text_color);
                             } else {
                                 imagestring($image_dst, $this->image_text_font, $text_x + ($this->image_text_alignment == 'l' ? 0 : ($t_width - strlen($v) * $char_width) / ($this->image_text_alignment == 'r' ? 1 : 2)), $text_y + $k * ($line_height + ($k > 0 && $k < sizeof($text) ? $this->image_text_line_spacing : 0)), $v, $text_color);
                             }
                         }
                     }
                 }
                 // add a reflection
                 if ($this->image_reflection_height) {
                     $this->log .= '- ' . _("add reflection") . ' : ' . $this->image_reflection_height . '<br />';
                     // we decode image_reflection_height, which can be a integer, a string in pixels or percentage
                     $image_reflection_height = $this->image_reflection_height;
                     if (strpos($image_reflection_height, '%') > 0) {
                         $image_reflection_height = $this->image_dst_y * str_replace('%', '', $image_reflection_height / 100);
                     }
                     if (strpos($image_reflection_height, 'px') > 0) {
                         $image_reflection_height = str_replace('px', '', $image_reflection_height);
                     }
                     $image_reflection_height = (int) $image_reflection_height;
                     if ($image_reflection_height > $this->image_dst_y) {
                         $image_reflection_height = $this->image_dst_y;
                     }
                     if (empty($this->image_reflection_color)) {
                         $this->image_reflection_color = '#FFFFFF';
                     }
                     if (empty($this->image_reflection_opacity)) {
                         $this->image_reflection_opacity = 60;
                     }
                     // create the new destination image
                     $tmp = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y + $image_reflection_height + $this->image_reflection_space);
                     sscanf($this->image_reflection_color, "#%2x%2x%2x", $red, $green, $blue);
                     $color = imagecolorallocate($tmp, $red, $green, $blue);
                     imagefilledrectangle($tmp, 0, 0, $this->image_dst_x, $this->image_dst_y + $image_reflection_height + $this->image_reflection_space, $color);
                     $transparency = $this->image_reflection_opacity;
                     // copy the original image
                     imagecopy($tmp, $image_dst, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0));
                     // copy the reflection
                     for ($y = 0; $y < $image_reflection_height; $y++) {
                         imagecopymerge($tmp, $image_dst, 0, $y + $this->image_dst_y + $this->image_reflection_space, 0, $this->image_dst_y - $y - 1 + ($this->image_reflection_space < 0 ? $this->image_reflection_space : 0), $this->image_dst_x, 1, (int) $transparency);
                         if ($transparency > 0) {
                             $transparency = $transparency - $this->image_reflection_opacity / $image_reflection_height;
                         }
                     }
                     // copy the resulting image into the destination image
                     $this->image_dst_y = $this->image_dst_y + $image_reflection_height + $this->image_reflection_space;
                     imagedestroy($image_dst);
                     $image_dst = imagecreatetruecolor($this->image_dst_x, $this->image_dst_y);
                     imagecopy($image_dst, $tmp, 0, 0, 0, 0, $this->image_dst_x, $this->image_dst_y);
                     imagedestroy($tmp);
                 }
                 if (is_numeric($this->jpeg_size) && $this->jpeg_size > 0 && ($this->image_convert == 'jpeg' || $this->image_convert == 'jpg')) {
                     // inspired by: JPEGReducer class version 1, 25 November 2004, Author: Huda M ElMatsani, justhuda at netscape dot net
                     $this->log .= '- ' . _("JPEG desired file size") . ' : ' . $this->jpeg_size . '<br />';
                     //calculate size of each image. 75%, 50%, and 25% quality
                     ob_start();
                     imagejpeg($image_dst, '', 75);
                     $buffer = ob_get_contents();
                     ob_end_clean();
                     $size75 = strlen($buffer);
                     ob_start();
                     imagejpeg($image_dst, '', 50);
                     $buffer = ob_get_contents();
                     ob_end_clean();
                     $size50 = strlen($buffer);
                     ob_start();
                     imagejpeg($image_dst, '', 25);
                     $buffer = ob_get_contents();
                     ob_end_clean();
                     $size25 = strlen($buffer);
                     //calculate gradient of size reduction by quality
                     $mgrad1 = 25 / ($size50 - $size25);
                     $mgrad2 = 25 / ($size75 - $size50);
                     $mgrad3 = 50 / ($size75 - $size25);
                     $mgrad = ($mgrad1 + $mgrad2 + $mgrad3) / 3;
                     //result of approx. quality factor for expected size
                     $q_factor = round($mgrad * ($this->jpeg_size - $size50) + 50);
                     if ($q_factor < 1) {
                         $this->jpeg_quality = 1;
                     } elseif ($q_factor > 100) {
                         $this->jpeg_quality = 100;
                     } else {
                         $this->jpeg_quality = $q_factor;
                     }
                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("JPEG quality factor set to") . ' ' . $this->jpeg_quality . '<br />';
                 }
                 // outputs image
                 $this->log .= '- ' . _("converting..") . '<br />';
                 switch ($this->image_convert) {
                     case 'jpeg':
                     case 'jpg':
                         $result = @imagejpeg($image_dst, $this->file_dst_pathname, $this->jpeg_quality);
                         if (!$result) {
                             $this->processed = false;
                             $this->error = _("No JPEG create support");
                         } else {
                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("JPEG image created") . '<br />';
                         }
                         break;
                     case 'png':
                         $result = @imagepng($image_dst, $this->file_dst_pathname);
                         if (!$result) {
                             $this->processed = false;
                             $this->error = _("No PNG create support");
                         } else {
                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("PNG image created") . '<br />';
                         }
                         break;
                     case 'gif':
                         $result = @imagegif($image_dst, $this->file_dst_pathname);
                         if (!$result) {
                             $this->processed = false;
                             $this->error = _("No GIF create support");
                         } else {
                             $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("GIF image created") . '<br />';
                         }
                         break;
                     default:
                         $this->processed = false;
                         $this->error = _("No convertion type defined");
                 }
                 if ($this->processed) {
                     if (is_resource($image_src)) {
                         imagedestroy($image_src);
                     }
                     if (is_resource($image_dst)) {
                         imagedestroy($image_dst);
                     }
                     $this->log .= '&nbsp;&nbsp;&nbsp;&nbsp;' . _("image objects destroyed") . '<br />';
                 }
             }
             if ($has_temp_file) {
                 $this->log .= '- ' . _("deletes temporary file") . '<br />';
                 @unlink($this->file_src_pathname);
             }
         } else {
             $this->log .= '- ' . _("no image processing wanted") . '<br />';
             if (!$this->no_upload_check) {
                 $result = is_uploaded_file($this->file_src_pathname);
             } else {
                 $result = TRUE;
             }
             if ($result) {
                 if (!$this->no_upload_check) {
                     if (!move_uploaded_file($this->file_src_pathname, $this->file_dst_pathname)) {
                         $this->processed = false;
                         $this->error = _("Error copying file on the server. move_uploaded_file() failed");
                     }
                 } else {
                     if (!copy($this->file_src_pathname, $this->file_dst_pathname)) {
                         $this->processed = false;
                         $this->error = _("Error copying file on the server. copy() failed");
                     }
                 }
             } else {
                 $this->processed = false;
                 $this->error = _("Error copying file on the server. Incorrect source file");
             }
         }
     }
     if ($this->processed) {
         $this->log .= '- <b>' . _("process OK") . '</b><br />';
     }
     // we reinit all the var
     $this->init();
 }
Example #14
0
 /**
  * Get the height of the text specified in pixels
  * @param string $text The text to calc the height for 
  * @return int The height of the text using the specified font 
  */
 function height($text)
 {
     return ImageFontHeight(IMAGE_GRAPH_FONT);
 }
Example #15
0
<?php

header('Content-type:image/jpeg');
if (isset($_GET['email'])) {
    $email = $_GET['email'];
} else {
    echo 'No Email Found';
}
$email_length = strlen($email);
$font_size = 4;
$image_height = ImageFontHeight($font_size);
$image_width = ImageFontWidth($font_size) * $email_length;
$image = imagecreate($image_width, $image_height);
imagecolorallocate($image, 255, 255, 255);
$font_color = imagecolorallocate($image, 0, 0, 0);
imagestring($image, $font_size, 0, 0, $email, $font_color);
imagejpeg($image);
Example #16
0
function DrawCoordinatGrid($arrayX, $arrayY, $width, $height, $ImageHandle, $bgColor = "FFFFFF", $gColor = 'B1B1B1', $Color = "000000", $dD = 15, $FontWidth = 2, $arrTTF_FONT = false)
{
    global $k, $xA, $yA, $xPixelLength, $yPixelLength, $APPLICATION;
    $arResult = array();
    $max_len = 0;
    $bUseTTFY = is_array($arrTTF_FONT["Y"]) && function_exists("ImageTTFText");
    $bUseTTFX = is_array($arrTTF_FONT["X"]) && function_exists("ImageTTFText");
    $ttf_font_y = "";
    $ttf_size_y = $ttf_shift_y = $ttf_base_y = 0;
    if ($bUseTTFY) {
        $ttf_font_y = $_SERVER["DOCUMENT_ROOT"] . $arrTTF_FONT["Y"]["FONT_PATH"];
        $ttf_size_y = $arrTTF_FONT["Y"]["FONT_SIZE"];
        $ttf_shift_y = $arrTTF_FONT["Y"]["FONT_SHIFT"];
        $ttf_base_y = 0;
        if (isset($arrTTF_FONT["Y"]["FONT_BASE"])) {
            $ttf_base_y = $arrTTF_FONT["Y"]["FONT_BASE"];
        }
        $dlataX = 0;
        foreach ($arrayY as $value) {
            $bbox = imagettfbbox($ttf_size_y, 0, $ttf_font_y, $value);
            $dlataX = max($dlataX, abs($bbox[2] - $bbox[0]) + 1);
        }
    } else {
        foreach ($arrayY as $value) {
            $max_len = max($max_len, strlen($value));
        }
        $dlataX = $max_len * ImageFontWidth($FontWidth);
    }
    $arr_bgColor = ReColor($bgColor);
    $colorFFFFFF = ImageColorAllocate($ImageHandle, $arr_bgColor[0], $arr_bgColor[1], $arr_bgColor[2]);
    $arr_Color = ReColor($Color);
    $color000000 = ImageColorAllocate($ImageHandle, $arr_Color[0], $arr_Color[1], $arr_Color[2]);
    $arr_gColor = ReColor($gColor);
    $colorCOCOCO = ImageColorAllocate($ImageHandle, $arr_gColor[0], $arr_gColor[1], $arr_gColor[2]);
    ImageFill($ImageHandle, 0, 0, $colorFFFFFF);
    $bForBarDiagram = is_array($arrTTF_FONT) && $arrTTF_FONT["type"] == "bar";
    if ($bForBarDiagram) {
        $arResult["XBUCKETS"] = array();
    }
    /*
    
    	Считаем точки для осей и координатной сетки
    
    	C
    	|
    	|
    	|
    	|
    	|__________________
    	A                 B
    */
    $ttf_font_x = "";
    $ttf_size_x = $ttf_shift_x = $ttf_base_x = 0;
    // координаты точки A
    $xA = $dD + $dlataX;
    if ($bUseTTFX) {
        $ttf_font_x = $_SERVER["DOCUMENT_ROOT"] . $arrTTF_FONT["X"]["FONT_PATH"];
        $ttf_size_x = $arrTTF_FONT["X"]["FONT_SIZE"];
        $ttf_shift_x = $arrTTF_FONT["X"]["FONT_SHIFT"];
        if (isset($arrTTF_FONT["X"]["FONT_BASE"])) {
            $ttf_base_x = $arrTTF_FONT["X"]["FONT_BASE"];
        }
        $yA = $height - $dD - $ttf_shift_x;
    } else {
        $yA = $height - $dD - ImageFontHeight($FontWidth) / 2;
    }
    // координаты точки C
    $xC = $xA;
    $yC = $dD;
    // координаты точки B
    $xB = $width - $dD;
    $yB = $yA;
    $GrafWidth = $xB - $xA;
    // ширина координатной сетки
    $GrafHeight = $yA - $yC;
    // высота координатной сетки
    $PointsX = max(sizeof($arrayX) + $bForBarDiagram, 2);
    // количество делений по оси X
    $PointsY = max(sizeof($arrayY), 2);
    // количество делений по оси Y
    $dX = $GrafWidth / ($PointsX - 1);
    // шаг сетки по X
    $dY = $GrafHeight / ($PointsY - 1);
    // шаг сетки по Y
    /*
    	Рисуем вертикальую сетку
    
    	C	P1
    	|	|
    	|	|
    	|	|
    	|	|
    	|___|______________
    	A	P0				B
    */
    $i = 0;
    $xP0 = $xA;
    $yP0 = $yA;
    $yP1 = $yC;
    while ($i < $PointsX) {
        if ($i == $PointsX - 1) {
            $xP0 = $xB;
        }
        $style = array($colorCOCOCO, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
        ImageSetStyle($ImageHandle, $style);
        ImageLine($ImageHandle, ceil($xP0), ceil($yP0), ceil($xP0), ceil($yP1), IMG_COLOR_STYLED);
        if ($bForBarDiagram) {
            $arResult["XBUCKETS"][$i] = array(ceil($xP0) + 1, ceil($xP0 + $dX) - 1);
        }
        $captionX = $arrayX[$i];
        // подписи по оси X
        $xCaption = $xP0 - strlen($captionX) * $k[$FontWidth] + $dX * $bForBarDiagram / 2;
        // координата X для подписи
        $yCaption = $yP0;
        // координата Y для подписи
        if ($bUseTTFX) {
            $bbox = imagettfbbox($ttf_size_x, 0, $ttf_font_x, $captionX);
            $ttf_width_x = abs($bbox[2] - $bbox[0]) + 1;
            $xCaption = $xP0 - $ttf_width_x / 2 + $dX * $bForBarDiagram / 2;
            $yCaption = $yP0 + $dD + $ttf_shift_x - $ttf_base_x;
            $captionX = $APPLICATION->ConvertCharset($captionX, LANG_CHARSET, "UTF-8");
            ImageTTFText($ImageHandle, $ttf_size_x, 0, $xCaption, $yCaption, $color000000, $ttf_font_x, $captionX);
        } else {
            ImageString($ImageHandle, $FontWidth, $xCaption, $yCaption + ImageFontHeight($FontWidth) / 2, $captionX, $color000000);
        }
        $xP0 += $dX;
        $i++;
    }
    /*
    	Рисуем горизонтальную сетку
    
       C
       |
       |
       |
     M1|___________________	M0
       |___________________
       A					B
    */
    $i = 0;
    $xM0 = $xB;
    $yM0 = $yB;
    $xM1 = $xA;
    $yM1 = $yA;
    while ($i < $PointsY) {
        if ($i == $PointsY - 1) {
            $yM0 = $yC;
            $yM1 = $yC;
        }
        if ($yM1 > 0 && $yM0 > 0) {
            $style = array($colorCOCOCO, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
            ImageSetStyle($ImageHandle, $style);
            ImageLine($ImageHandle, ceil($xM0), ceil($yM0), ceil($xM1), ceil($yM1), IMG_COLOR_STYLED);
            $captionY = $arrayY[$i];
            // подписи по оси Y
            $xCaption = $dlataX;
            // координата X для подписи
            $yCaption = $yM1 - $k[$FontWidth] * 3;
            // координата Y для подписи
            if ($bUseTTFY) {
                $captionY = $APPLICATION->ConvertCharset($captionY, LANG_CHARSET, "UTF-8");
                $bbox = imagettfbbox($ttf_size_y, 0, $ttf_font_y, $captionY);
                $yCaption = $yM1 + ($ttf_shift_y - $ttf_base_y) / 2;
                ImageTTFText($ImageHandle, $ttf_size_y, 0, $xCaption - abs($bbox[2] - $bbox[0]) - 1, $yCaption, $color000000, $ttf_font_y, $captionY);
            } else {
                ImageString($ImageHandle, $FontWidth, $xCaption - strlen($captionY) * ImageFontWidth($FontWidth), $yCaption, $captionY, $color000000);
            }
        }
        $yM0 -= $dY;
        $yM1 -= $dY;
        $i++;
    }
    // рисуем оси X и Y
    ImageLine($ImageHandle, ceil($xA), ceil($yA), ceil($xC), ceil($yC), $color000000);
    ImageLine($ImageHandle, ceil($xB), ceil($yB), ceil($xA), ceil($yA), $color000000);
    $xPixelLength = $xB - $xA;
    // ширина поля для графика
    $yPixelLength = $yA - $yC;
    // высота поля для графика
    $arResult["VIEWPORT"] = array(ceil($xA), ceil($yA), ceil($xB), ceil($yC));
    return $arResult;
}
Example #17
0
 function SetFontGD($which_elem, $which_font, $which_spacing = NULL)
 {
     if ($which_font < 1 || 5 < $which_font) {
         return $this->PrintError(__FUNCTION__ . ': Font size must be 1, 2, 3, 4 or 5');
     }
     if (!$this->CheckOption($which_elem, 'generic, title, legend, x_label, y_label, x_title, y_title', __FUNCTION__)) {
         return FALSE;
     }
     # Store the font parameters: name/size, char cell height and width.
     $this->fonts[$which_elem] = array('ttf' => FALSE, 'font' => $which_font, 'height' => ImageFontHeight($which_font), 'width' => ImageFontWidth($which_font), 'line_spacing' => $which_spacing);
     return TRUE;
 }
Example #18
0
 public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color = '000000', $ttffont = '', $opacity = 100, $margin = 5, $angle = 0, $bg_color = false, $bg_opacity = 0, $fillextend = '')
 {
     // text watermark requested
     if (!$text) {
         return false;
     }
     ImageAlphaBlending($gdimg, true);
     if (preg_match('#^([0-9\\.\\-]*)x([0-9\\.\\-]*)(@[LCR])?$#i', $alignment, $matches)) {
         $originOffsetX = intval($matches[1]);
         $originOffsetY = intval($matches[2]);
         $alignment = @$matches[4] ? $matches[4] : 'L';
         $margin = 0;
     } else {
         $originOffsetX = 0;
         $originOffsetY = 0;
     }
     $metaTextArray = array('^Fb' => $this->phpThumbObject->getimagesizeinfo['filesize'], '^Fk' => round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1024), '^Fm' => round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1048576), '^X' => $this->phpThumbObject->getimagesizeinfo[0], '^Y' => $this->phpThumbObject->getimagesizeinfo[1], '^x' => ImageSX($gdimg), '^y' => ImageSY($gdimg), '^^' => '^');
     $text = strtr($text, $metaTextArray);
     $text = str_replace("\r\n", "\n", $text);
     $text = str_replace("\r", "\n", $text);
     $textlines = explode("\n", $text);
     $this->DebugMessage('Processing ' . count($textlines) . ' lines of text', __FILE__, __LINE__);
     if (@is_readable($ttffont) && is_file($ttffont)) {
         $opacity = 100 - intval(max(min($opacity, 100), 0));
         $letter_color_text = phpthumb_functions::ImageHexColorAllocate($gdimg, $hex_color, false, $opacity * 1.27);
         $this->DebugMessage('Using TTF font "' . $ttffont . '"', __FILE__, __LINE__);
         $TTFbox = ImageTTFbBox($size, $angle, $ttffont, $text);
         $min_x = min($TTFbox[0], $TTFbox[2], $TTFbox[4], $TTFbox[6]);
         $max_x = max($TTFbox[0], $TTFbox[2], $TTFbox[4], $TTFbox[6]);
         //$text_width = round($max_x - $min_x + ($size * 0.5));
         $text_width = round($max_x - $min_x);
         $min_y = min($TTFbox[1], $TTFbox[3], $TTFbox[5], $TTFbox[7]);
         $max_y = max($TTFbox[1], $TTFbox[3], $TTFbox[5], $TTFbox[7]);
         //$text_height = round($max_y - $min_y + ($size * 0.5));
         $text_height = round($max_y - $min_y);
         $TTFboxChar = ImageTTFbBox($size, $angle, $ttffont, 'jH');
         $char_min_y = min($TTFboxChar[1], $TTFboxChar[3], $TTFboxChar[5], $TTFboxChar[7]);
         $char_max_y = max($TTFboxChar[1], $TTFboxChar[3], $TTFboxChar[5], $TTFboxChar[7]);
         $char_height = round($char_max_y - $char_min_y);
         if ($alignment == '*') {
             $text_origin_y = $char_height + $margin;
             while ($text_origin_y - $text_height < ImageSY($gdimg)) {
                 $text_origin_x = $margin;
                 while ($text_origin_x < ImageSX($gdimg)) {
                     ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
                     $text_origin_x += $text_width + $margin;
                 }
                 $text_origin_y += $text_height + $margin;
             }
         } else {
             // this block for background color only
             switch ($alignment) {
                 case '*':
                     // handled separately
                     break;
                 case 'T':
                     $text_origin_x = $originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2);
                     $text_origin_y = $char_height + $margin + $originOffsetY;
                     break;
                 case 'B':
                     $text_origin_x = $originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2);
                     $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
                     break;
                 case 'L':
                     $text_origin_x = $margin + $originOffsetX;
                     $text_origin_y = $originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                     break;
                 case 'R':
                     $text_origin_x = $originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                     $text_origin_y = $originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                     break;
                 case 'C':
                     $text_origin_x = $originOffsetX ? $originOffsetX - round($text_width / 2) : round((ImageSX($gdimg) - $text_width) / 2);
                     $text_origin_y = $originOffsetY ? $originOffsetY : round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                     break;
                 case 'TL':
                     $text_origin_x = $margin + $originOffsetX;
                     $text_origin_y = $char_height + $margin + $originOffsetY;
                     break;
                 case 'TR':
                     $text_origin_x = $originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                     $text_origin_y = $char_height + $margin + $originOffsetY;
                     break;
                 case 'BL':
                     $text_origin_x = $margin + $originOffsetX;
                     $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
                     break;
                 case 'BR':
                 default:
                     $text_origin_x = $originOffsetX ? $originOffsetX - $text_width : ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                     $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin + $originOffsetY;
                     break;
             }
             //ImageRectangle($gdimg, $text_origin_x + $min_x, $text_origin_y + $TTFbox[1], $text_origin_x + $min_x + $text_width, $text_origin_y + $TTFbox[1] - $text_height, $letter_color_text);
             if (phpthumb_functions::IsHexColor($bg_color)) {
                 $text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
                 $text_color_background = phpthumb_functions::ImageHexColorAllocate($gdimg, $bg_color, false, $text_background_alpha);
             } else {
                 $text_color_background = phpthumb_functions::ImageHexColorAllocate($gdimg, 'FFFFFF', false, 127);
             }
             $x1 = $text_origin_x + $min_x;
             $y1 = $text_origin_y + $TTFbox[1];
             $x2 = $text_origin_x + $min_x + $text_width;
             $y2 = $text_origin_y + $TTFbox[1] - $text_height;
             $x_TL = preg_match('#x#i', $fillextend) ? 0 : min($x1, $x2);
             $y_TL = preg_match('#y#i', $fillextend) ? 0 : min($y1, $y2);
             $x_BR = preg_match('#x#i', $fillextend) ? ImageSX($gdimg) : max($x1, $x2);
             $y_BR = preg_match('#y#i', $fillextend) ? ImageSY($gdimg) : max($y1, $y2);
             //while ($y_BR > ImageSY($gdimg)) {
             //	$y_TL--;
             //	$y_BR--;
             //	$text_origin_y--;
             //}
             $this->DebugMessage('WatermarkText() calling ImageFilledRectangle($gdimg, ' . $x_TL . ', ' . $y_TL . ', ' . $x_BR . ', ' . $y_BR . ', $text_color_background)', __FILE__, __LINE__);
             ImageFilledRectangle($gdimg, $x_TL, $y_TL, $x_BR, $y_BR, $text_color_background);
             // end block for background color only
             $y_offset = 0;
             foreach ($textlines as $dummy => $line) {
                 $TTFboxLine = ImageTTFbBox($size, $angle, $ttffont, $line);
                 $min_x_line = min($TTFboxLine[0], $TTFboxLine[2], $TTFboxLine[4], $TTFboxLine[6]);
                 $max_x_line = max($TTFboxLine[0], $TTFboxLine[2], $TTFboxLine[4], $TTFboxLine[6]);
                 //$text_width = round($max_x - $min_x + ($size * 0.5));
                 $text_width_line = round($max_x_line - $min_x_line);
                 $min_y_line = min($TTFboxLine[1], $TTFboxLine[3], $TTFboxLine[5], $TTFboxLine[7]);
                 $max_y_line = max($TTFboxLine[1], $TTFboxLine[3], $TTFboxLine[5], $TTFboxLine[7]);
                 //$text_height = round($max_y - $min_y + ($size * 0.5));
                 $text_height_line = round($max_y_line - $min_y_line);
                 switch ($alignment) {
                     // $text_origin_y set above, just re-set $text_origin_x here as needed
                     case 'L':
                     case 'TL':
                     case 'BL':
                         // no change neccesary
                         break;
                     case 'C':
                     case 'T':
                     case 'B':
                         $text_origin_x = $originOffsetX ? $originOffsetX - round($text_width_line / 2) : round((ImageSX($gdimg) - $text_width_line) / 2);
                         break;
                     case 'R':
                     case 'TR':
                     case 'BR':
                         $text_origin_x = $originOffsetX ? $originOffsetX - $text_width_line : ImageSX($gdimg) - $text_width_line + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                         break;
                 }
                 //ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
                 $this->DebugMessage('WatermarkText() calling ImageTTFtext($gdimg, ' . $size . ', ' . $angle . ', ' . $text_origin_x . ', ' . ($text_origin_y + $y_offset) . ', $letter_color_text, ' . $ttffont . ', ' . $line . ')', __FILE__, __LINE__);
                 ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y + $y_offset, $letter_color_text, $ttffont, $line);
                 $y_offset += $char_height;
             }
         }
         return true;
     } else {
         $size = min(5, max(1, $size));
         $this->DebugMessage('Using built-in font (size=' . $size . ') for text watermark' . ($ttffont ? ' because $ttffont !is_readable(' . $ttffont . ')' : ''), __FILE__, __LINE__);
         $text_width = 0;
         $text_height = 0;
         foreach ($textlines as $dummy => $line) {
             $text_width = max($text_width, ImageFontWidth($size) * strlen($line));
             $text_height += ImageFontHeight($size);
         }
         if ($img_watermark = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
             ImageAlphaBlending($img_watermark, false);
             if (phpthumb_functions::IsHexColor($bg_color)) {
                 $text_background_alpha = round(127 * ((100 - min(max(0, $bg_opacity), 100)) / 100));
                 $text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, $bg_color, false, $text_background_alpha);
             } else {
                 $text_color_background = phpthumb_functions::ImageHexColorAllocate($img_watermark, 'FFFFFF', false, 127);
             }
             $this->DebugMessage('WatermarkText() calling ImageFilledRectangle($img_watermark, 0, 0, ' . ImageSX($img_watermark) . ', ' . ImageSY($img_watermark) . ', $text_color_background)', __FILE__, __LINE__);
             ImageFilledRectangle($img_watermark, 0, 0, ImageSX($img_watermark), ImageSY($img_watermark), $text_color_background);
             if ($angle && function_exists('ImageRotate')) {
                 // using $img_watermark_mask is pointless if ImageRotate function isn't available
                 if ($img_watermark_mask = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
                     $mask_color_background = ImageColorAllocate($img_watermark_mask, 0, 0, 0);
                     ImageAlphaBlending($img_watermark_mask, false);
                     ImageFilledRectangle($img_watermark_mask, 0, 0, ImageSX($img_watermark_mask), ImageSY($img_watermark_mask), $mask_color_background);
                     $mask_color_watermark = ImageColorAllocate($img_watermark_mask, 255, 255, 255);
                 }
             }
             $text_color_watermark = phpthumb_functions::ImageHexColorAllocate($img_watermark, $hex_color);
             foreach ($textlines as $key => $line) {
                 switch ($alignment) {
                     case 'C':
                         $x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
                         $originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
                         $originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
                         break;
                     case 'T':
                         $x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
                         $originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
                         $originOffsetY = $margin;
                         break;
                     case 'B':
                         $x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
                         $originOffsetX = (ImageSX($gdimg) - ImageSX($img_watermark)) / 2;
                         $originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
                         break;
                     case 'L':
                         $x_offset = 0;
                         $originOffsetX = $margin;
                         $originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
                         break;
                     case 'TL':
                         $x_offset = 0;
                         $originOffsetX = $margin;
                         $originOffsetY = $margin;
                         break;
                     case 'BL':
                         $x_offset = 0;
                         $originOffsetX = $margin;
                         $originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
                         break;
                     case 'R':
                         $x_offset = $text_width - ImageFontWidth($size) * strlen($line);
                         $originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
                         $originOffsetY = (ImageSY($gdimg) - ImageSY($img_watermark)) / 2;
                         break;
                     case 'TR':
                         $x_offset = $text_width - ImageFontWidth($size) * strlen($line);
                         $originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
                         $originOffsetY = $margin;
                         break;
                     case 'BR':
                     default:
                         if (!empty($originOffsetX) || !empty($originOffsetY)) {
                             // absolute pixel positioning
                         } else {
                             $x_offset = $text_width - ImageFontWidth($size) * strlen($line);
                             $originOffsetX = ImageSX($gdimg) - ImageSX($img_watermark) - $margin;
                             $originOffsetY = ImageSY($gdimg) - ImageSY($img_watermark) - $margin;
                         }
                         break;
                 }
                 $this->DebugMessage('WatermarkText() calling ImageString($img_watermark, ' . $size . ', ' . $x_offset . ', ' . $key * ImageFontHeight($size) . ', ' . $line . ', $text_color_watermark)', __FILE__, __LINE__);
                 ImageString($img_watermark, $size, $x_offset, $key * ImageFontHeight($size), $line, $text_color_watermark);
                 if ($angle && $img_watermark_mask) {
                     $this->DebugMessage('WatermarkText() calling ImageString($img_watermark_mask, ' . $size . ', ' . $x_offset . ', ' . $key * ImageFontHeight($size) . ', ' . $text . ', $mask_color_watermark)', __FILE__, __LINE__);
                     ImageString($img_watermark_mask, $size, $x_offset, $key * ImageFontHeight($size), $text, $mask_color_watermark);
                 }
             }
             if ($angle && $img_watermark_mask) {
                 $img_watermark = ImageRotate($img_watermark, $angle, $text_color_background);
                 $img_watermark_mask = ImageRotate($img_watermark_mask, $angle, $mask_color_background);
                 phpthumb_filters::ApplyMask($img_watermark_mask, $img_watermark);
             }
             //phpthumb_filters::WatermarkOverlay($gdimg, $img_watermark, $alignment, $opacity, $margin);
             $this->DebugMessage('WatermarkText() calling phpthumb_filters::WatermarkOverlay($gdimg, $img_watermark, ' . ($originOffsetX . 'x' . $originOffsetY) . ', ' . $opacity . ', 0)', __FILE__, __LINE__);
             phpthumb_filters::WatermarkOverlay($gdimg, $img_watermark, $originOffsetX . 'x' . $originOffsetY, $opacity, 0);
             ImageDestroy($img_watermark);
             return true;
         }
     }
     return false;
 }
Example #19
0
/**
*  создание заглушки holder для <IMG>
*  цвет задавать как в HTML в полном формате #RRGGBB
*  если цвет = rand то он формируется случайным образом
*  текст только английский (кодировка latin2)
*  если $text = true, то выводится размер изображения ШШхВВ
*  
*  @param $width ширина
*  @param $height высота
*  @param $text текст
*  @param $background_color цвет фона
*  @param $text_color цвет текста
*  @param $font_size размер шрифта от 1 до 5
*  
*  @return string
*  
*  <img src="<?= mso_holder() ? >" -> в формате data:image/png;base64, 
*  mso_holder(250, 80)
*  mso_holder(300, 50, 'My text', '#660000', '#FFFFFF')
*  mso_holder(600, 400, 'Slide', 'rand', 'rand')
*/
function mso_holder($width = 100, $height = 100, $text = true, $background_color = '#CCCCCC', $text_color = '#777777', $font_size = 5)
{
    $im = @imagecreate($width, $height) or die("Cannot initialize new GD image stream");
    $color = mso_hex2rgb($background_color);
    $bg = imagecolorallocate($im, $color['red'], $color['green'], $color['blue']);
    $color = mso_hex2rgb($text_color);
    $tc = imagecolorallocate($im, $color['red'], $color['green'], $color['blue']);
    if ($text) {
        if ($text === true) {
            $text = $width . 'x' . $height;
        }
        $center_x = ceil((imagesx($im) - ImageFontWidth($font_size) * mb_strlen($text)) / 2);
        $center_y = ceil((imagesy($im) - ImageFontHeight($font_size)) / 2);
        imagestring($im, $font_size, $center_x, $center_y, $text, $tc);
    }
    ob_start();
    imagepng($im);
    $src = 'data:image/png;base64,' . base64_encode(ob_get_contents());
    ob_end_clean();
    imagedestroy($im);
    return $src;
}
Example #20
0
 function Diagramm($im, $VALUES, $LEGEND)
 {
     //GLOBAL $COLORS,$SHADOWS;
     $black = ImageColorAllocate($im, 0, 0, 0);
     // Получим размеры изображения
     $W = ImageSX($im);
     $H = ImageSY($im);
     // Вывод легенды #####################################
     // Посчитаем количество пунктов, от этого зависит высота легенды
     //$legend_count=count($LEGEND);
     $legend_count = $this->ucount;
     // Посчитаем максимальную длину пункта, от этого зависит ширина легенды
     $max_length = 0;
     foreach ($LEGEND as $v) {
         if ($max_length < strlen($v)) {
             $max_length = strlen($v);
         }
     }
     // Номер шрифта, котором мы будем выводить легенду
     $FONT = 2;
     $font_w = ImageFontWidth($FONT);
     $font_h = ImageFontHeight($FONT);
     // Вывод прямоугольника - границы легенды ----------------------------
     $l_width = $font_w * $max_length + $font_h + 10 + 5 + 10;
     $l_height = $font_h * $legend_count + 10 + 10;
     // Получим координаты верхнего левого угла прямоугольника - границы легенды
     $l_x1 = $W - 10 - $l_width;
     $l_y1 = ($H - $l_height) / 2;
     // Выводя прямоугольника - границы легенды
     //ImageRectangle($im, $l_x1, $l_y1, $l_x1+$l_width, $l_y1+$l_height, $black);
     // Вывод текст легенды и цветных квадратиков
     $text_x = $l_x1 + 10 + 5 + $font_h;
     $square_x = $l_x1 + 10;
     $y = $l_y1 + 10;
     $i = 0;
     foreach ($LEGEND as $v) {
         $dy = $y + $i * $font_h;
         ImageString($im, $FONT, $text_x, $dy, $v, $black);
         ImageFilledRectangle($im, $square_x + 1, $dy + 1, $square_x + $font_h - 1, $dy + $font_h - 1, $this->COLORS[$i]);
         ImageRectangle($im, $square_x + 1, $dy + 1, $square_x + $font_h - 1, $dy + $font_h - 1, $black);
         $i++;
     }
     // Вывод круговой диаграммы ----------------------------------------
     $total = array_sum($VALUES);
     $anglesum = $angle = array(0);
     $i = 1;
     // Расчет углов
     while ($i < count($VALUES)) {
         $part = $VALUES[$i - 1] / $total;
         $angle[$i] = floor($part * 360);
         $anglesum[$i] = array_sum($angle);
         $i++;
     }
     $anglesum[] = $anglesum[0];
     // Расчет диаметра
     //	$diametr=$l_x1-10-10;
     $diametr = $l_x1 - 10 - 10;
     // Расчет координат центра эллипса
     $circle_x = $diametr / 2 + 10;
     $circle_y = $H / 2 - 10;
     // Поправка диаметра, если эллипс не помещается по высоте
     if ($diametr > $H * 2 - 10 - 10) {
         $diametr = $H * 2 - 20 - 20 - 40;
     }
     // Вывод тени
     for ($j = 20; $j > 0; $j--) {
         for ($i = 0; $i < count($anglesum) - 1; $i++) {
             ImageFilledArc($im, $circle_x, $circle_y + $j, $diametr, $diametr / 2, $anglesum[$i], $anglesum[$i + 1], $this->SHADOWS[$i], IMG_ARC_PIE);
         }
     }
     // Вывод круговой диаграммы
     for ($i = 0; $i < count($anglesum) - 1; $i++) {
         ImageFilledArc($im, $circle_x, $circle_y, $diametr, $diametr / 2, $anglesum[$i], $anglesum[$i + 1], $this->COLORS[$i], IMG_ARC_PIE);
     }
 }
 function ErrorImage($text, $width = 400, $height = 100)
 {
     $this->error = $text;
     if (!$this->config_error_die_on_error) {
         return true;
     }
     if (!empty($this->err) || !empty($this->config_error_message_image_default)) {
         // Show generic custom error image instead of error message
         // for use on production sites where you don't want debug messages
         if (@$this->err == 'showerror') {
             // fall through and actually show error message even if default error image is set
         } else {
             header('Location: ' . (!empty($this->err) ? $this->err : $this->config_error_message_image_default));
             exit;
         }
     }
     if (@$this->f == 'text') {
         // bypass all GD functions and output text error message
         die('<PRE>' . $text . '</PRE>');
     }
     $FontWidth = ImageFontWidth($this->config_error_fontsize);
     $FontHeight = ImageFontHeight($this->config_error_fontsize);
     $LinesOfText = explode("\n", wordwrap($text, floor($width / $FontWidth), "\n", true));
     $height = max($height, count($LinesOfText) * $FontHeight);
     if (headers_sent()) {
         echo "\n" . '**Headers already sent, dumping error message as text:**<br>' . "\n\n" . $text;
     } elseif ($gdimg_error = @ImageCreate($width, $height)) {
         $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_bgcolor, true);
         $text_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_textcolor, true);
         ImageFilledRectangle($gdimg_error, 0, 0, $width, $height, $background_color);
         $lineYoffset = 0;
         foreach ($LinesOfText as $line) {
             ImageString($gdimg_error, $this->config_error_fontsize, 2, $lineYoffset, $line, $text_color);
             $lineYoffset += $FontHeight;
         }
         if (function_exists('ImageTypes')) {
             $imagetypes = ImageTypes();
             if ($imagetypes & IMG_PNG) {
                 header('Content-type: image/png');
                 ImagePNG($gdimg_error);
             } elseif ($imagetypes & IMG_GIF) {
                 header('Content-type: image/gif');
                 ImageGIF($gdimg_error);
             } elseif ($imagetypes & IMG_JPG) {
                 header('Content-type: image/jpeg');
                 ImageJPEG($gdimg_error);
             } elseif ($imagetypes & IMG_WBMP) {
                 header('Content-type: image/wbmp');
                 ImageWBMP($gdimg_error);
             }
         }
         ImageDestroy($gdimg_error);
     }
     if (!headers_sent()) {
         echo "\n" . '**Failed to send graphical error image, dumping error message as text:**<br>' . "\n\n" . $text;
     }
     exit;
     return true;
 }
Example #22
0
    /**
     * Output the element to the canvas
     * @see Image_Graph_Common 
     * @access private
     */
    function _done()
    {
        if (is_a($this->_fillStyle, "Image_Graph_Fill")) {
            $this->_fillStyle->_reset();
        }
                
        if ($this->_background != null) {
            $this->_debug("Drawing background");
            ImageFilledRectangle($this->_canvas(), $this->_left, $this->_top, $this->_right, $this->_bottom, $this->_getBackground());
        }

        if ($this->_identify) {
            $this->_debug("Identifying");
            $red = rand(0, 255);
            $green = rand(0, 255);
            $blue = rand(0, 255);
            $color = ImageColorAllocate($this->_canvas(), $red, $green, $blue);
            if (isset($GLOBALS['_Image_Graph_gd2'])) {
                $alphaColor = ImageColorResolveAlpha($this->_canvas(), $red, $green, $blue, 200);
            } else {
                $alphaColor = $color;
            }

            ImageRectangle($this->_canvas(), $this->_left, $this->_top, $this->_right, $this->_bottom, $color);
            ImageFilledRectangle($this->_canvas(), $this->_left, $this->_top, $this->_right, $this->_bottom, $alphaColor);

            if ($this->_identifyText) {
                $text = eregi_replace("<[^>]*>([^<]*)", "\\1", $this->_identification());
                if (ImageFontWidth(IMAGE_GRAPH_FONT) * strlen($text) > $this->width()) {
                    $x = max($this->_left, min($this->_right, $this->_left + ($this->width() - ImageFontHeight(IMAGE_GRAPH_FONT)) / 2));
                    $y = max($this->_top, min($this->_bottom, $this->_bottom - ($this->height() - ImageFontWidth(IMAGE_GRAPH_FONT) * strlen($text)) / 2));
                    ImageStringUp($this->_canvas(), FONT, $x, $y, $text, $color);
                } else {
                    $x = max($this->_left, min($this->_right, $this->_left + ($this->width() - ImageFontWidth(IMAGE_GRAPH_FONT) * strlen($text)) / 2));
                    $y = max($this->_top, min($this->_bottom, $this->_top + ($this->height() - ImageFontHeight(IMAGE_GRAPH_FONT)) / 2));
                    ImageString($this->_canvas(), FONT, $x, $y, $text, $color);
                }
            }
        }

        if ($this->_borderStyle != null) {
            $this->_debug("Drawing border");
            ImageRectangle($this->_canvas(), $this->_left, $this->_top, $this->_right, $this->_bottom, ((is_a($this->_borderStyle, "Image_Graph_Color")) ? $this->_borderStyle->_index : $this->_borderStyle->_getLineStyle()));
        }
        parent::_done();
        
        if ($this->_shadow) {
            $this->_displayShadow();
        }
    }
 function DrawXDataLabel($xlab, $xpos)
 {
     //xpos comes in in PIXELS not in world coordinates.
     //Draw an x data label centered at xlab
     if ($this->use_ttf) {
         $xlab_size = $this->TTFBBoxSize($this->axis_ttffont_size, $this->x_datalabel_angle, $this->axis_ttffont, $xlab);
         //An array
         $y = $this->plot_area[3] + $xlab_size[1] + 4;
         //in pixels
         $x = $xpos - $xlab_size[0] / 2;
         ImageTTFText($this->img, $this->axis_ttffont_size, $this->x_datalabel_angle, $x, $y, $this->ndx_text_color, $this->axis_ttffont, $xlab);
     } else {
         $xlab_size = array(ImageFontWidth($this->axis_font) * StrLen($xlab), $this->small_font_height * 3);
         if ($this->x_datalabel_angle == 90) {
             $y = $this->plot_area[3] + ImageFontWidth($this->axis_font) * StrLen($xlab);
             //in pixels
             $x = $xpos - $this->small_font_height;
             ImageStringUp($this->img, $this->axis_font, $x, $y, $xlab, $this->ndx_text_color);
         } else {
             $y = $this->plot_area[3] + ImageFontHeight($this->axis_font);
             //in pixels
             $x = $xpos - ImageFontWidth($this->axis_font) * StrLen($xlab) / 2;
             ImageString($this->img, $this->axis_font, $x, $y, $xlab, $this->ndx_text_color);
         }
     }
 }
Example #24
0
 function ErrorImage($text, $width = 0, $height = 0, $forcedisplay = false)
 {
     $width = $width ? $width : $this->config_error_image_width;
     $height = $height ? $height : $this->config_error_image_height;
     $text = 'phpThumb() v' . $this->phpthumb_version . "\n" . 'http://phpthumb.sourceforge.net' . "\n\n" . ($this->config_disable_debug ? 'Error messages disabled' : $text);
     $this->FatalError($text);
     $this->DebugMessage($text, __FILE__, __LINE__);
     $this->purgeTempFiles();
     if ($this->phpThumbDebug && !$forcedisplay) {
         return false;
     }
     if (!$this->config_error_die_on_error && !$forcedisplay) {
         return false;
     }
     if ($this->config_error_silent_die_on_error) {
         exit;
     }
     if ($this->err || $this->config_error_message_image_default) {
         // Show generic custom error image instead of error message
         // for use on production sites where you don't want debug messages
         if ($this->err == 'showerror' || $this->phpThumbDebug) {
             // fall through and actually show error message even if default error image is set
         } else {
             header('Location: ' . ($this->err ? $this->err : $this->config_error_message_image_default));
             exit;
         }
     }
     $this->setOutputFormat();
     if (!$this->thumbnailFormat || phpthumb_functions::gd_version() < 1) {
         $this->thumbnailFormat = 'text';
     }
     if (@$this->thumbnailFormat == 'text') {
         // bypass all GD functions and output text error message
         if (!headers_sent()) {
             header('Content-type: text/plain');
             echo $text;
         } else {
             echo '<pre>' . htmlspecialchars($text) . '</pre>';
         }
         exit;
     }
     $FontWidth = ImageFontWidth($this->config_error_fontsize);
     $FontHeight = ImageFontHeight($this->config_error_fontsize);
     $LinesOfText = explode("\n", @wordwrap($text, floor($width / $FontWidth), "\n", true));
     $height = max($height, count($LinesOfText) * $FontHeight);
     $headers_file = '';
     $headers_line = '';
     if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.0', '>=') && headers_sent($headers_file, $headers_line)) {
         echo "\n" . '**Headers already sent in file "' . $headers_file . '" on line "' . $headers_line . '", dumping error message as text:**<br><pre>' . "\n\n" . $text . "\n" . '</pre>';
     } elseif (headers_sent()) {
         echo "\n" . '**Headers already sent, dumping error message as text:**<br><pre>' . "\n\n" . $text . "\n" . '</pre>';
     } elseif ($gdimg_error = ImageCreate($width, $height)) {
         $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_bgcolor, true);
         $text_color = phpthumb_functions::ImageHexColorAllocate($gdimg_error, $this->config_error_textcolor, true);
         ImageFilledRectangle($gdimg_error, 0, 0, $width, $height, $background_color);
         $lineYoffset = 0;
         foreach ($LinesOfText as $line) {
             ImageString($gdimg_error, $this->config_error_fontsize, 2, $lineYoffset, $line, $text_color);
             $lineYoffset += $FontHeight;
         }
         if (function_exists('ImageTypes')) {
             $imagetypes = ImageTypes();
             if ($imagetypes & IMG_PNG) {
                 header('Content-Type: image/png');
                 ImagePNG($gdimg_error);
             } elseif ($imagetypes & IMG_GIF) {
                 header('Content-Type: image/gif');
                 ImageGIF($gdimg_error);
             } elseif ($imagetypes & IMG_JPG) {
                 header('Content-Type: image/jpeg');
                 ImageJPEG($gdimg_error);
             } elseif ($imagetypes & IMG_WBMP) {
                 header('Content-Type: image/vnd.wap.wbmp');
                 ImageWBMP($gdimg_error);
             }
         }
         ImageDestroy($gdimg_error);
     }
     if (!headers_sent()) {
         echo "\n" . '**Failed to send graphical error image, dumping error message as text:**<br>' . "\n\n" . $text;
     }
     exit;
     return true;
 }
Example #25
0
 public static function Barcode39($barcode, $width, $height, $quality, $text, $path)
 {
     $im = ImageCreate($width, $height) or die("Cannot Initialize new GD image stream");
     $White = ImageColorAllocate($im, 255, 255, 255);
     $Black = ImageColorAllocate($im, 0, 0, 0);
     //ImageColorTransparent ($im, $White);
     ImageInterLace($im, 1);
     $NarrowRatio = 20;
     $WideRatio = 55;
     $QuietRatio = 35;
     $nChars = (strlen($barcode) + 2) * (6 * $NarrowRatio + 3 * $WideRatio + $QuietRatio);
     $Pixels = $width / $nChars;
     $NarrowBar = (int) (20 * $Pixels);
     $WideBar = (int) (55 * $Pixels);
     $QuietBar = (int) (35 * $Pixels);
     $ActualWidth = ($NarrowBar * 6 + $WideBar * 3 + $QuietBar) * (strlen($barcode) + 2);
     if ($NarrowBar == 0 || $NarrowBar == $WideBar || $NarrowBar == $QuietBar || $WideBar == 0 || $WideBar == $QuietBar || $QuietBar == 0) {
         ImageString($im, 1, 0, 0, "Image is too small!", $Black);
         OutputImage($im, $format, $quality);
         exit;
     }
     $CurrentBarX = (int) (($width - $ActualWidth) / 2);
     $Color = $White;
     $BarcodeFull = "*" . strtoupper($barcode) . "*";
     settype($BarcodeFull, "string");
     $FontNum = 3;
     $FontHeight = ImageFontHeight($FontNum);
     $FontWidth = ImageFontWidth($FontNum);
     if ($text != 0) {
         $CenterLoc = (int) (($width - 1) / 2) - (int) ($FontWidth * strlen($BarcodeFull) / 2);
         ImageString($im, $FontNum, $CenterLoc, $height - $FontHeight, "{$BarcodeFull}", $Black);
     } else {
         $FontHeight = -2;
     }
     for ($i = 0; $i < strlen($BarcodeFull); $i++) {
         $StripeCode = self::Code39($BarcodeFull[$i]);
         for ($n = 0; $n < 9; $n++) {
             if ($Color == $White) {
                 $Color = $Black;
             } else {
                 $Color = $White;
             }
             switch ($StripeCode[$n]) {
                 case '0':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $NarrowBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $NarrowBar;
                     break;
                 case '1':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $WideBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $WideBar;
                     break;
             }
         }
         $Color = $White;
         ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $QuietBar, $height - 1 - $FontHeight - 2, $Color);
         $CurrentBarX += $QuietBar;
     }
     return ImageJPEG($im, $path, $quality);
 }
Example #26
0
function debugMode($line, $message, $file = null, $config = null, $message2 = null)
{
    global $im, $configData;
    // Destroy the image
    if (isset($im)) {
        imageDestroy($im);
    }
    if (is_numeric($line)) {
        $line -= 1;
    }
    $error_text = 'Error!';
    $line_text = 'Line: ' . $line;
    $file = !empty($file) ? 'File: ' . $file : '';
    $config = $config ? 'Check the config file' : '';
    $message2 = !empty($message2) ? $message2 : '';
    $lines = array();
    $lines[] = array('s' => $error_text, 'f' => 5, 'c' => 'red');
    $lines[] = array('s' => $line_text, 'f' => 3, 'c' => 'blue');
    $lines[] = array('s' => $file, 'f' => 2, 'c' => 'green');
    $lines[] = array('s' => $message, 'f' => 2, 'c' => 'black');
    $lines[] = array('s' => $config, 'f' => 2, 'c' => 'black');
    $lines[] = array('s' => $message2, 'f' => 2, 'c' => 'black');
    $height = $width = 0;
    foreach ($lines as $line) {
        if (strlen($line['s']) > 0) {
            $line_width = ImageFontWidth($line['f']) * strlen($line['s']);
            $width = $width < $line_width ? $line_width : $width;
            $height += ImageFontHeight($line['f']);
        }
    }
    $im = @imagecreate($width + 1, $height);
    if ($im) {
        $white = imagecolorallocate($im, 255, 255, 255);
        $red = imagecolorallocate($im, 255, 0, 0);
        $green = imagecolorallocate($im, 0, 255, 0);
        $blue = imagecolorallocate($im, 0, 0, 255);
        $black = imagecolorallocate($im, 0, 0, 0);
        $linestep = 0;
        foreach ($lines as $line) {
            if (strlen($line['s']) > 0) {
                imagestring($im, $line['f'], 1, $linestep, utf8_to_nce($line['s']), ${$line}['c']);
                $linestep += ImageFontHeight($line['f']);
            }
        }
        switch ($configData['image_type']) {
            case 'jpeg':
            case 'jpg':
                header('Content-type: image/jpg');
                @imageJpeg($im);
                break;
            case 'png':
                header('Content-type: image/png');
                @imagePng($im);
                break;
            case 'gif':
            default:
                header('Content-type: image/gif');
                @imagegif($im);
                break;
        }
        imageDestroy($im);
    } else {
        if (!empty($file)) {
            $file = "[<span style=\"color:green\">{$file}</span>]";
        }
        $string = "<strong><span style=\"color:red\">Error!</span></strong>";
        $string .= "<span style=\"color:blue\">Line {$line}:</span> {$message} {$file}\n<br /><br />\n";
        if ($config) {
            $string .= "{$config}\n<br />\n";
        }
        if (!empty($message2)) {
            $string .= "{$message2}\n";
        }
        print $string;
    }
    exit;
}
Example #27
0
<?php

header('Content-type: image/jpeg');
$email = "*****@*****.**";
$len = strlen($email);
$font_size = 4;
$width = ImageFontWidth($len * 4);
$height = ImageFontHeight(4);
$image = imagecreate($width . $height);
imagecolorlocator($image, 255, 255, 255);
$font_color = imagefontlocator($image, 0, 0, 0);
imagestring($image, $font_size, 0, 0, $email, $font_color);
imagejpeg($image);
    $font = $_SERVER["DOCUMENT_ROOT"]."/HDWFormCaptcha/".$font;
if (!file_exists($font))
    $font = dirname(__FILE__)."/".$font;   
*/
$font_size = rand($min_size, $max_size);
$angle = rand(-15, 15);
if (function_exists("imagettfbbox") && function_exists("imagettftext")) {
    $box = imagettfbbox($font_size, $angle, $font, $str);
    $x = (int) ($imgX - $box[4]) / 2;
    $y = (int) ($imgY - $box[5]) / 2;
    imagettftext($image, $font_size, $angle, $x, $y, $text_col, $font, $str);
} else {
    if (function_exists("imageFtBBox") && function_exists("imageFTText")) {
        $box = imageFtBBox($font_size, $angle, $font, $str);
        $x = (int) ($imgX - $box[4]) / 2;
        $y = (int) ($imgY - $box[5]) / 2;
        imageFTText($image, $font_size, $angle, $x, $y, $text_col, $font, $str);
    } else {
        $angle = 0;
        $font = 6;
        $wf = ImageFontWidth(6) * strlen($str);
        $hf = ImageFontHeight(6);
        $x = (int) ($imgX - $wf) / 2;
        $y = (int) ($imgY - $hf) / 2;
        imagestring($image, $font, $x, $y, $str, $text_col);
    }
}
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
exit;
Example #29
0
 function SetFont($which_elem, $which_font, $which_size = 12)
 {
     // TTF:
     if ($this->use_ttf) {
         // Empty font name means use the default font.
         if (empty($which_font)) {
             $which_font = $this->default_ttfont;
         }
         $path = $which_font;
         // First try the font name directly, if not then try with path.
         if (!is_file($path) || !is_readable($path)) {
             $path = $this->ttf_path . '/' . $which_font;
             if (!is_file($path) || !is_readable($path)) {
                 $this->DrawError("SetFont(): Can't find TrueType font {$which_font}");
                 return FALSE;
             }
         }
         switch ($which_elem) {
             case 'generic':
                 $this->generic_font['font'] = $path;
                 $this->generic_font['size'] = $which_size;
                 break;
             case 'title':
                 $this->title_font['font'] = $path;
                 $this->title_font['size'] = $which_size;
                 break;
             case 'legend':
                 $this->legend_font['font'] = $path;
                 $this->legend_font['size'] = $which_size;
                 break;
             case 'x_label':
                 $this->x_label_font['font'] = $path;
                 $this->x_label_font['size'] = $which_size;
                 break;
             case 'y_label':
                 $this->y_label_font['font'] = $path;
                 $this->y_label_font['size'] = $which_size;
                 break;
             case 'x_title':
                 $this->x_title_font['font'] = $path;
                 $this->x_title_font['size'] = $which_size;
                 break;
             case 'y_title':
                 $this->y_title_font['font'] = $path;
                 $this->y_title_font['size'] = $which_size;
                 break;
             default:
                 $this->DrawError("SetFont(): Unknown element '{$which_elem}' specified.");
                 return FALSE;
         }
         return TRUE;
     }
     // Fixed fonts:
     if ($which_font > 5 || $which_font < 0) {
         $this->DrawError('SetFont(): Non-TTF font size must be 1, 2, 3, 4 or 5');
         return FALSE;
     }
     switch ($which_elem) {
         case 'generic':
             $this->generic_font['font'] = $which_font;
             $this->generic_font['height'] = ImageFontHeight($which_font);
             $this->generic_font['width'] = ImageFontWidth($which_font);
             break;
         case 'title':
             $this->title_font['font'] = $which_font;
             $this->title_font['height'] = ImageFontHeight($which_font);
             $this->title_font['width'] = ImageFontWidth($which_font);
             break;
         case 'legend':
             $this->legend_font['font'] = $which_font;
             $this->legend_font['height'] = ImageFontHeight($which_font);
             $this->legend_font['width'] = ImageFontWidth($which_font);
             break;
         case 'x_label':
             $this->x_label_font['font'] = $which_font;
             $this->x_label_font['height'] = ImageFontHeight($which_font);
             $this->x_label_font['width'] = ImageFontWidth($which_font);
             break;
         case 'y_label':
             $this->y_label_font['font'] = $which_font;
             $this->y_label_font['height'] = ImageFontHeight($which_font);
             $this->y_label_font['width'] = ImageFontWidth($which_font);
             break;
         case 'x_title':
             $this->x_title_font['font'] = $which_font;
             $this->x_title_font['height'] = ImageFontHeight($which_font);
             $this->x_title_font['width'] = ImageFontWidth($which_font);
             break;
         case 'y_title':
             $this->y_title_font['font'] = $which_font;
             $this->y_title_font['height'] = ImageFontHeight($which_font);
             $this->y_title_font['width'] = ImageFontWidth($which_font);
             break;
         default:
             $this->DrawError("SetFont(): Unknown element '{$which_elem}' specified.");
             return FALSE;
     }
     return TRUE;
 }
Example #30
0
 function GetFontHeight($font)
 {
     return ImageFontHeight($font);
 }