예제 #1
0
 public function handle($urls)
 {
     $images = $this->session->get('images') ?: array();
     foreach ($urls as $path) {
         if (isset($images[$path])) {
             continue;
         }
         $fileHeaders = @get_headers($path);
         if (!$fileHeaders || $fileHeaders[7] == 'HTTP/1.1 404 Not Found' || $fileHeaders[0] == 'HTTP/1.1 404 Not Found') {
             continue;
         }
         if (exif_imagetype($path) != IMAGETYPE_JPEG) {
             continue;
         }
         $images[$path]['id'] = uniqid();
         list($width, $height) = getimagesize($path);
         $newHeight = self::HEIGHT;
         $newWidth = $width * $newHeight / $height;
         $images[$path]['width'] = $newWidth;
         $thumb = imagecreatetruecolor($newWidth, $newHeight);
         $source = imagecreatefromjpeg($path);
         imagecopyresized($thumb, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
         $imgSrc = self::SRC . $images[$path]['id'] . '.jpg';
         $images[$path]['src'] = $imgSrc;
         $newImage = __DIR__ . '/../../../../web' . $imgSrc;
         // Черный цвет для текста на картинке
         $color = ImageColorAllocate($thumb, 0, 0, 0);
         // Нанесении текста на картинку в нижнем левом углу
         ImageTTFtext($thumb, 13, 0, 3, self::HEIGHT - 3, $color, "Times", "Treto Test");
         imagejpeg($thumb, $newImage);
         ImageDestroy($thumb);
         ImageDestroy($source);
     }
     $this->session->set('images', $images);
     return $images;
 }
예제 #2
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;
 }
예제 #3
0
 function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color = '000000', $ttffont = '', $opacity = 100, $margin = 5, $angle = 0)
 {
     // text watermark requested
     if (!$text) {
         return false;
     }
     ImageAlphaBlending($gdimg, true);
     $text = str_replace("\r\n", "\n", $text);
     $text = str_replace("\r", "\n", $text);
     $textlines = explode("\n", $text);
     if (@is_readable($ttffont) && is_file($ttffont)) {
         $opacity = 100 - intval(max(min($opacity, 100), 0));
         $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, 'pH');
         $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);
         switch ($alignment) {
             case 'T':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = $char_height + $margin;
                 break;
             case 'B':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = ImageSY($gdimg) - $TTFbox[1] - $margin;
                 break;
             case 'L':
                 $text_origin_x = $margin;
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                 break;
             case 'R':
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                 break;
             case 'C':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                 break;
             case 'TL':
                 $text_origin_x = $margin;
                 $text_origin_y = $char_height + $margin;
                 break;
             case 'TR':
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = $char_height + $margin;
                 break;
             case 'BL':
                 $text_origin_x = $margin;
                 $text_origin_y = ImageSY($gdimg) - $TTFbox[1] - $margin;
                 break;
             case 'BR':
             default:
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = ImageSY($gdimg) - $TTFbox[1] - $margin;
                 break;
         }
         $letter_color_text = phpthumb_functions::ImageHexColorAllocate($gdimg, $hex_color, false, $opacity * 1.27);
         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 {
             //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);
             ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
         }
         return true;
         //if ($img_watermark = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
         //	if ($img_watermark_mask = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
         //		$letter_color_background      = phpthumb_functions::ImageColorAllocateAlphaSafe($img_watermark,      127, 127, 127, 127);
         //		$letter_color_background_mask = phpthumb_functions::ImageColorAllocateAlphaSafe($img_watermark_mask, 127, 127, 127, 127);
         //		ImageFilledRectangle($img_watermark,      0, 0, ImageSX($img_watermark),      ImageSY($img_watermark),      $letter_color_background);
         //		ImageFilledRectangle($img_watermark_mask, 0, 0, ImageSX($img_watermark_mask), ImageSY($img_watermark_mask), $letter_color_background_mask);
         //
         //		$letter_color_watermark = phpthumb_functions::ImageHexColorAllocate($img_watermark, $hex_color);
         //		$letter_color_watermark_mask = ImageColorAllocate($img_watermark_mask, 255, 255, 255);
         //
         //		ImageTTFtext($img_watermark,      $size, $angle, $TTFbox[0] - $min_x + round($size * 0.25), $TTFbox[1] - $min_y,  $letter_color_watermark,      $ttffont, $text);
         //		ImageTTFtext($img_watermark_mask, $size, $angle, $TTFbox[0] - $min_x + round($size * 0.25), $TTFbox[1] - $min_y, -$letter_color_watermark_mask, $ttffont, $text);
         //
         //		$this->ApplyMask($img_watermark_mask, $img_watermark);
         //		$this->WatermarkOverlay($gdimg, $img_watermark, $alignment, $opacity, $margin);
         //
         //		ImageDestroy($img_watermark);
         //		ImageDestroy($img_watermark_mask);
         //		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 $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);
             $text_color_background = phpthumb_functions::ImageColorAllocateAlphaSafe($img_watermark, 255, 255, 255, 127);
             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':
                     case 'T':
                     case 'B':
                         $x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
                         break;
                     case 'L':
                     case 'TL':
                     case 'BL':
                         $x_offset = 0;
                         break;
                     case 'R':
                     case 'TR':
                     case 'BR':
                     default:
                         $x_offset = $text_width - ImageFontWidth($size) * strlen($line);
                         break;
                 }
                 ImageString($img_watermark, $size, $x_offset, $key * ImageFontHeight($size), $line, $text_color_watermark);
                 if ($angle && $img_watermark_mask) {
                     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);
             ImageDestroy($img_watermark);
             return true;
         }
     }
     return false;
 }
예제 #4
0
 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);
     $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);
     if (@is_readable($ttffont) && is_file($ttffont)) {
         $opacity = 100 - intval(max(min($opacity, 100), 0));
         $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);
         switch ($alignment) {
             case 'T':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = $char_height + $margin;
                 break;
             case 'B':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin;
                 break;
             case 'L':
                 $text_origin_x = $margin;
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                 break;
             case 'R':
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                 break;
             case 'C':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $char_height;
                 break;
             case 'TL':
                 $text_origin_x = $margin;
                 $text_origin_y = $char_height + $margin;
                 break;
             case 'TR':
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = $char_height + $margin;
                 break;
             case 'BL':
                 $text_origin_x = $margin;
                 $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin;
                 break;
             case 'BR':
             default:
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = ImageSY($gdimg) + $TTFbox[1] - $margin;
                 break;
         }
         $letter_color_text = phpthumb_functions::ImageHexColorAllocate($gdimg, $hex_color, false, $opacity * 1.27);
         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 {
             //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 = eregi('x', $fillextend) ? 0 : min($x1, $x2);
             $y_TL = eregi('y', $fillextend) ? 0 : min($y1, $y2);
             $x_BR = eregi('x', $fillextend) ? ImageSX($gdimg) : max($x1, $x2);
             $y_BR = eregi('y', $fillextend) ? ImageSY($gdimg) : max($y1, $y2);
             //while ($y_BR > ImageSY($gdimg)) {
             //	$y_TL--;
             //	$y_BR--;
             //	$text_origin_y--;
             //}
             ImageFilledRectangle($gdimg, $x_TL, $y_TL, $x_BR, $y_BR, $text_color_background);
             ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
         }
         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);
             }
             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':
                     case 'T':
                     case 'B':
                         $x_offset = round(($text_width - ImageFontWidth($size) * strlen($line)) / 2);
                         break;
                     case 'L':
                     case 'TL':
                     case 'BL':
                         $x_offset = 0;
                         break;
                     case 'R':
                     case 'TR':
                     case 'BR':
                     default:
                         $x_offset = $text_width - ImageFontWidth($size) * strlen($line);
                         break;
                 }
                 ImageString($img_watermark, $size, $x_offset, $key * ImageFontHeight($size), $line, $text_color_watermark);
                 if ($angle && $img_watermark_mask) {
                     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);
             ImageDestroy($img_watermark);
             return true;
         }
     }
     return false;
 }
 function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color = '000000', $ttffont = '', $opacity = 100, $margin = 5, $angle = 0)
 {
     // text watermark requested
     if (!$text) {
         return false;
     }
     $opacity = max(min($opacity, 100), 0);
     if (@is_readable($ttffont) && is_file($ttffont)) {
         $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);
         switch ($alignment) {
             case 'T':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = $text_height + $margin;
                 break;
             case 'B':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = ImageSY($gdimg) - $text_height + $TTFbox[1] - $min_y - $margin;
                 break;
             case 'L':
                 $text_origin_x = $margin;
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $text_height;
                 break;
             case 'R':
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $text_height;
                 break;
             case 'C':
                 $text_origin_x = round((ImageSX($gdimg) - $text_width) / 2);
                 $text_origin_y = round((ImageSY($gdimg) - $text_height) / 2) + $text_height;
                 break;
             case 'TL':
                 $text_origin_x = $margin;
                 $text_origin_y = $text_height + $margin;
                 break;
             case 'TR':
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = $text_height + $margin;
                 break;
             case 'BL':
                 $text_origin_x = $margin;
                 $text_origin_y = ImageSY($gdimg) - $text_height + $TTFbox[1] - $min_y - $margin;
                 break;
             case 'BR':
             default:
                 $text_origin_x = ImageSX($gdimg) - $text_width + $TTFbox[0] - $min_x + round($size * 0.25) - $margin;
                 $text_origin_y = ImageSY($gdimg) - $text_height + $TTFbox[1] - $min_y - $margin;
                 break;
         }
         $letter_color_text = phpthumb_functions::ImageHexColorAllocate($gdimg, $hex_color, $opacity * 1.27);
         if ($alignment == '*') {
             $text_origin_y = $text_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 {
             ImageTTFtext($gdimg, $size, $angle, $text_origin_x, $text_origin_y, $letter_color_text, $ttffont, $text);
         }
         return true;
         //if ($img_watermark = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
         //	if ($img_watermark_mask = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
         //		$letter_color_background      = ImageColorAllocateAlpha($img_watermark,      127, 127, 127, 127);
         //		$letter_color_background_mask = ImageColorAllocateAlpha($img_watermark_mask, 127, 127, 127, 127);
         //		ImageFilledRectangle($img_watermark,      0, 0, ImageSX($img_watermark),      ImageSY($img_watermark),      $letter_color_background);
         //		ImageFilledRectangle($img_watermark_mask, 0, 0, ImageSX($img_watermark_mask), ImageSY($img_watermark_mask), $letter_color_background_mask);
         //
         //		$letter_color_watermark = phpthumb_functions::ImageHexColorAllocate($img_watermark, $hex_color);
         //		$letter_color_watermark_mask = ImageColorAllocate($img_watermark_mask, 255, 255, 255);
         //
         //		ImageTTFtext($img_watermark,      $size, $angle, $TTFbox[0] - $min_x + round($size * 0.25), $TTFbox[1] - $min_y,  $letter_color_watermark,      $ttffont, $text);
         //		ImageTTFtext($img_watermark_mask, $size, $angle, $TTFbox[0] - $min_x + round($size * 0.25), $TTFbox[1] - $min_y, -$letter_color_watermark_mask, $ttffont, $text);
         //
         //		$this->ApplyMask($img_watermark_mask, $img_watermark);
         //		$this->WatermarkOverlay($gdimg, $img_watermark, $alignment, $opacity, $margin);
         //
         //		ImageDestroy($img_watermark);
         //		ImageDestroy($img_watermark_mask);
         //		return true;
         //	}
         //}
     } else {
         if ($ttffont) {
             //$this->DebugMessage('Using built-in font for text watermark because $ttffont !is_readable('.$ttffont.')', __FILE__, __LINE__);
         }
         $size = min(5, max(1, $size));
         $text_width = ImageFontWidth($size) * strlen($text);
         $text_height = ImageFontHeight($size);
         if ($img_watermark = phpthumb_functions::ImageCreateFunction($text_width, $text_height)) {
             ImageAlphaBlending($img_watermark, false);
             $text_color_background = ImageColorAllocateAlpha($img_watermark, 255, 255, 255, 127);
             ImageFilledRectangle($img_watermark, 0, 0, ImageSX($img_watermark), ImageSY($img_watermark), $text_color_background);
             $text_color_watermark = phpthumb_functions::ImageHexColorAllocate($img_watermark, $hex_color);
             ImageString($img_watermark, $size, 0, 0, $text, $text_color_watermark);
             if ($angle) {
                 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);
                     ImageString($img_watermark_mask, $size, 0, 0, $text, $mask_color_watermark);
                     $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);
             ImageDestroy($img_watermark);
             return true;
         }
     }
     return false;
 }
예제 #6
0
 /**
  * @see CaptchaInterface
  */
 public function render($str, $params)
 {
     $hex = $params['background'][mt_rand(0, count($params['background']) - 1)];
     $bgColor = $this->hexToRgb($hex);
     $hex = $params['colors'][mt_rand(0, count($params['colors']) - 1)];
     $textColor = $this->hexToRgb($hex);
     //Prototype
     $img1 = imagecreatetruecolor($params['width'], $params['height']);
     imagefill($img1, 0, 0, imagecolorallocate($img1, $bgColor['r'], $bgColor['g'], $bgColor['b']));
     //Distorted picture (multi-wave)
     $img2 = imagecreatetruecolor($params['width'], $params['height']);
     //Print text
     $x = ($params['width'] - strlen($str) * ($params['letterSpacing'] + $params['fontSize'] * 0.66)) / 2;
     for ($i = 0; $i < strlen($str); $i++) {
         ImageTTFtext($img1, $params['fontSize'], 0, $x, ceil(($params['height'] + $params['fontSize']) / 2), imagecolorallocate($img1, $textColor['r'], $textColor['g'], $textColor['b']), $params['font'], $str[$i]);
         $x += ceil($params['fontSize'] * 0.66) + $params['letterSpacing'];
     }
     //Scratches (background color)
     for ($i = 0; $i < $params['scratches']; $i++) {
         $k = floor($params['width'] / 10);
         imageline($img1, floor($params['width'] / $params['scratches'] * $i), mt_rand(1, $params['height']), floor($params['width'] / $params['scratches'] * $i) + $k, mt_rand(1, $params['height']), imagecolorallocate($img1, $bgColor['r'], $bgColor['g'], $bgColor['b']));
     }
     //Scratch (text color)
     imageline($img1, mt_rand(0, floor($params['width'] / 2)), mt_rand(1, $params['height']), mt_rand(floor($params['width'] / 2), $params['width']), mt_rand(1, $params['height']), imagecolorallocate($img1, $textColor['r'], $textColor['g'], $textColor['b']));
     $sxR1 = mt_rand(7, 10) / 120;
     $syR1 = mt_rand(7, 10) / 120;
     $sxR2 = mt_rand(7, 10) / 120;
     $syR2 = mt_rand(7, 10) / 120;
     $sxF1 = mt_rand(0, 314) / 100;
     $sxF2 = mt_rand(0, 314) / 100;
     $syF1 = mt_rand(0, 314) / 100;
     $syF2 = mt_rand(0, 314) / 100;
     $sxA = mt_rand(4, 6);
     $syA = mt_rand(4, 6);
     for ($x = 0; $x < $params['width']; $x++) {
         for ($y = 0; $y < $params['height']; $y++) {
             $sx = $x + (sin($x * $sxR1 + $sxF1) + sin($y * $sxR2 + $sxF2)) * $sxA;
             $sy = $y + (sin($x * $syR1 + $syF1) + sin($y * $syR2 + $syF2)) * $syA;
             if ($sx < 0 || $sy < 0 || $sx >= $params['width'] - 1 || $sy >= $params['height'] - 1) {
                 $r = $rX = $rY = $rXY = $bgColor['r'];
                 $g = $gX = $gY = $gXY = $bgColor['g'];
                 $b = $bX = $bY = $bXY = $bgColor['b'];
             } else {
                 $rgb = imagecolorat($img1, $sx, $sy);
                 $r = $rgb >> 16 & 0xff;
                 $g = $rgb >> 8 & 0xff;
                 $b = $rgb & 0xff;
                 $rgb = imagecolorat($img1, $sx + 1, $sy);
                 $rX = $rgb >> 16 & 0xff;
                 $gX = $rgb >> 8 & 0xff;
                 $bX = $rgb & 0xff;
                 $rgb = imagecolorat($img1, $sx, $sy + 1);
                 $rY = $rgb >> 16 & 0xff;
                 $gY = $rgb >> 8 & 0xff;
                 $bY = $rgb & 0xff;
                 $rgb = imagecolorat($img1, $sx + 1, $sy + 1);
                 $rXY = $rgb >> 16 & 0xff;
                 $gXY = $rgb >> 8 & 0xff;
                 $bXY = $rgb & 0xff;
             }
             if ($r == $rX && $r == $rY && $r == $rXY && $g == $gX && $g == $gY && $g == $gXY && $b == $bX && $b == $bY && $b == $bXY) {
                 if ($r == $bgColor['r'] && $g == $bgColor['g'] && $b == $bgColor['b']) {
                     $newR = $bgColor['r'];
                     $newG = $bgColor['g'];
                     $newB = $bgColor['b'];
                 } else {
                     $newR = $textColor['r'];
                     $newG = $textColor['g'];
                     $newB = $textColor['b'];
                 }
             } else {
                 $frsx = $sx - floor($sx);
                 $frsy = $sy - floor($sy);
                 $frsx1 = 1 - $frsx;
                 $frsy1 = 1 - $frsy;
                 $newR = floor($r * $frsx1 * $frsy1 + $rX * $frsx * $frsy1 + $rY * $frsx1 * $frsy + $rXY * $frsx * $frsy);
                 $newG = floor($g * $frsx1 * $frsy1 + $gX * $frsx * $frsy1 + $gY * $frsx1 * $frsy + $gXY * $frsx * $frsy);
                 $newB = floor($b * $frsx1 * $frsy1 + $bX * $frsx * $frsy1 + $bY * $frsx1 * $frsy + $bXY * $frsx * $frsy);
             }
             imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newR, $newG, $newB));
         }
     }
     ob_start();
     imagepng($img2);
     $content = ob_get_contents();
     ob_end_clean();
     imagedestroy($img1);
     imagedestroy($img2);
     return $content;
 }