Ejemplo n.º 1
0
 public function generate()
 {
     $src_x = $this->_owner->getImageWidth();
     $src_y = $this->_owner->getImageHeight();
     $old_x = $this->_owner->getImageWidth();
     $old_y = $this->_owner->getImageHeight();
     //Resize the image to be a set size proportionate to the aspect ratio
     //Default to the old size
     $canvas_x = $old_x;
     $canvas_y = $old_y;
     if ($this->_resize_x > 0 and $this->_resize_y > 0) {
         $canvas_x = $this->_resize_x;
         $canvas_y = $this->_resize_y;
     } elseif ($this->_resize_x > 0) {
         if ($this->_resize_x < $old_x) {
             $canvas_x = $this->_resize_x;
             $canvas_y = floor($this->_resize_x / $old_x * $old_y);
         }
     } elseif ($this->_resize_y > 0) {
         if ($this->_resize_y < $old_y) {
             $canvas_x = floor($this->_resize_y / $old_y * $old_x);
             $canvas_y = $this->_resize_y;
         }
     }
     $dst_x = $canvas_x;
     $dst_y = $canvas_y;
     $dst = new Canvas();
     $dst->createImageTrueColorTransparent($dst_x, $dst_y);
     imagecopyresampled($dst->image, $this->_owner->image, 0, 0, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
     $this->_owner->image = $dst->image;
     unset($dst);
     return true;
 }
Ejemplo n.º 2
0
 public function generate()
 {
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     $matrix = $this->_matrix;
     $matrix_width = count($matrix);
     $matrix_sum = array_sum($matrix);
     $m_offset = floor($matrix_width / 2);
     $p1 = $p2 = array();
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             $color = Color::intColorToArrayColor($this->_owner->imageColorAt($x, $y));
             $p1[$x][$y]['r'] = $color['red'];
             $p1[$x][$y]['g'] = $color['green'];
             $p1[$x][$y]['b'] = $color['blue'];
             $p1[$x][$y]['a'] = $color['alpha'];
             $p2[$x][$y]['r'] = 255;
             $p2[$x][$y]['g'] = 255;
             $p2[$x][$y]['b'] = 255;
             $p2[$x][$y]['a'] = 127;
         }
     }
     $temp = new Canvas();
     $temp->createImageTrueColorTransparent($width, $height);
     imagesavealpha($temp->image, true);
     imagealphablending($temp->image, true);
     for ($i = $m_offset; $i < $width - $m_offset; $i++) {
         for ($j = $m_offset; $j < $height - $m_offset; $j++) {
             $sumr = $sumg = $sumb = $suma = 0;
             for ($k = 0; $k < $matrix_width; $k++) {
                 $xx = $i - ($matrix_width >> 1) + $k;
                 $sumr += $p1[$xx][$j]['r'] * $matrix[$k];
                 $sumg += $p1[$xx][$j]['g'] * $matrix[$k];
                 $sumb += $p1[$xx][$j]['b'] * $matrix[$k];
                 $suma += $p1[$xx][$j]['a'] * $matrix[$k];
             }
             $p2[$i][$j]['r'] = $sumr / $matrix_sum;
             $p2[$i][$j]['g'] = $sumg / $matrix_sum;
             $p2[$i][$j]['b'] = $sumb / $matrix_sum;
             $p2[$i][$j]['a'] = $suma / $matrix_sum;
         }
     }
     for ($i = $m_offset; $i < $width - $m_offset; $i++) {
         for ($j = $m_offset; $j < $height - $m_offset; $j++) {
             $sumr = $sumg = $sumb = $suma = 0;
             for ($k = 0; $k < $matrix_width; $k++) {
                 $xy = $j - ($matrix_width >> 1) + $k;
                 $sumr += $p2[$i][$xy]['r'] * $matrix[$k];
                 $sumg += $p2[$i][$xy]['g'] * $matrix[$k];
                 $sumb += $p2[$i][$xy]['b'] * $matrix[$k];
                 $suma += $p2[$i][$xy]['a'] * $matrix[$k];
             }
             $col = imagecolorallocatealpha($temp->image, $sumr / $matrix_sum, $sumg / $matrix_sum, $sumb / $matrix_sum, $suma / $matrix_sum);
             imagesetpixel($temp->image, $i, $j, $col);
         }
     }
     $this->_owner->image = $temp->image;
     unset($temp);
     return true;
 }
Ejemplo n.º 3
0
 public function generate()
 {
     $src_x = $this->_owner->getImageWidth();
     $src_y = $this->_owner->getImageHeight();
     $temp = new Canvas();
     $temp->createImageTrueColorTransparent($src_x, $src_y + 20);
     $text = str_replace('[Filename]', $this->_owner->getProperty('filename'), $this->_info);
     switch ($this->_position) {
         case 't':
             $x = 0;
             $y = 20;
             $bar_y = 0;
             $text_y = 3;
             break;
         case 'b':
             $x = 0;
             $y = 0;
             $bar_y = $src_y + 20;
             $text_y = $bar_y - 20 + 3;
             break;
         default:
             return false;
             break;
     }
     switch ($this->_justify) {
         case 'l':
             $text_x = 3;
             break;
         case 'c':
             $text_x = ($src_x - imagefontwidth($this->_font) * strlen($text)) / 2;
             break;
         case 'r':
             $text_x = $src_x - 3 - imagefontwidth($this->_font) * strlen($text);
             break;
     }
     //Draw the bar background
     $color = Color::hexColorToArrayColor($this->_barcolor);
     $bar_color = imagecolorallocate($temp->image, $color['red'], $color['green'], $color['blue']);
     imagefilledrectangle($temp->image, 0, $bar_y, $src_x, 20, $bar_color);
     //Copy the image
     imagecopy($temp->image, $this->_owner->image, $x, $y, 0, 0, $src_x, $src_y);
     //Draw the text (to be replaced with image_draw_text one day
     $color = Color::hexColorToArrayColor($this->_textcolor);
     $text_color = imagecolorallocate($temp->image, $color['red'], $color['green'], $color['blue']);
     imagestring($temp->image, $this->_font, $text_x, $text_y, $text, $text_color);
     $this->_owner->image = $temp->image;
     unset($temp);
     return true;
 }
Ejemplo n.º 4
0
 public function generate()
 {
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     $temp = new Canvas();
     if (!empty($this->_color)) {
         $temp->createImageTrueColor($width + ($this->_right + $this->_left), $height + ($this->_top + $this->_bottom));
         $arrColor = Color::hexColorToArrayColor($this->_color);
         $tempcolor = imagecolorallocate($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue']);
         imagefilledrectangle($temp->image, 0, 0, $temp->getImageWidth(), $temp->getImageHeight(), $tempcolor);
     } else {
         $temp->createImageTrueColorTransparent($width + ($this->_right + $this->_left), $height + ($this->_top + $this->_bottom));
     }
     imagecopy($temp->image, $this->_owner->image, $this->_left, $this->_top, 0, 0, $width, $height);
     $this->_owner->image = $temp->image;
     unset($temp);
     return true;
 }
Ejemplo n.º 5
0
 public function generate()
 {
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     //Calculate the cropping area
     if ($this->_crop_x > 0 && $width > $this->_crop_x) {
         $width = $this->_crop_x;
     }
     if ($this->_crop_y > 0 && $height > $this->_crop_y) {
         $height = $this->_crop_y;
     }
     $crop = new Canvas();
     $crop->createImageTrueColorTransparent($width, $height);
     $src_width = $this->_owner->getHandleX() - floor($width / 2);
     $src_height = $this->_owner->getHandleY() - floor($height / 2);
     imagecopy($crop->image, $this->_owner->image, 0, 0, $src_width, $src_height, $width, $height);
     $this->_owner->image = $crop->image;
     unset($crop);
     return true;
 }
Ejemplo n.º 6
0
 public function generate()
 {
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     // default values
     $checkTransparency = false;
     // define borders to trim away
     if (is_null($this->_away)) {
         $this->_away = array('top', 'right', 'bottom', 'left');
     } elseif (is_string($this->_away)) {
         $this->_away = array($this->_away);
     }
     // lower border names
     foreach ($this->_away as $key => $value) {
         $this->_away[$key] = strtolower($value);
     }
     // define base color position
     switch (strtolower($this->_base)) {
         case 'transparent':
         case 'trans':
             $checkTransparency = true;
             $base_x = 0;
             $base_y = 0;
             break;
         case 'bottom-right':
         case 'right-bottom':
             $base_x = $width - 1;
             $base_y = $height - 1;
             break;
         default:
         case 'top-left':
         case 'left-top':
             $base_x = 0;
             $base_y = 0;
             break;
     }
     // pick base color
     if ($checkTransparency) {
         // color will only be used to compare alpha channel
         $color = array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 0);
     } else {
         $color = Color::intColorToArrayColor($this->_owner->imageColorAt($base_x, $base_y));
     }
     $top_x = 0;
     $top_y = 0;
     $bottom_x = $width;
     $bottom_y = $height;
     // search upper part of image for colors to trim away
     if (in_array('top', $this->_away)) {
         for ($y = 0; $y < ceil($height / 2); $y++) {
             for ($x = 0; $x < $width; $x++) {
                 $checkColor = Color::intColorToArrayColor($this->_owner->imageColorAt($x, $y));
                 if ($checkTransparency) {
                     $checkColor['red'] = $color['red'];
                     $checkColor['green'] = $color['green'];
                     $checkColor['blue'] = $color['blue'];
                 }
                 if (Color::differs($color, $checkColor, $this->_tolerance)) {
                     $top_y = max(0, $y - $this->_feather);
                     break 2;
                 }
             }
         }
     }
     // search left part of image for colors to trim away
     if (in_array('left', $this->_away)) {
         for ($x = 0; $x < ceil($width / 2); $x++) {
             for ($y = $top_y; $y < $height; $y++) {
                 $checkColor = Color::intColorToArrayColor($this->_owner->imageColorAt($x, $y));
                 if ($checkTransparency) {
                     $checkColor['red'] = $color['red'];
                     $checkColor['green'] = $color['green'];
                     $checkColor['blue'] = $color['blue'];
                 }
                 if (Color::differs($color, $checkColor, $this->_tolerance)) {
                     $top_x = max(0, $x - $this->_feather);
                     break 2;
                 }
             }
         }
     }
     // search lower part of image for colors to trim away
     if (in_array('bottom', $this->_away)) {
         for ($y = $height - 1; $y >= floor($height / 2) - 1; $y--) {
             for ($x = $top_x; $x < $width; $x++) {
                 $checkColor = Color::intColorToArrayColor($this->_owner->imageColorAt($x, $y));
                 if ($checkTransparency) {
                     $checkColor['red'] = $color['red'];
                     $checkColor['green'] = $color['green'];
                     $checkColor['blue'] = $color['blue'];
                 }
                 if (Color::differs($color, $checkColor, $this->_tolerance)) {
                     $bottom_y = min($height, $y + 1 + $this->_feather);
                     break 2;
                 }
             }
         }
     }
     // search right part of image for colors to trim away
     if (in_array('right', $this->_away)) {
         for ($x = $width - 1; $x >= floor($width / 2) - 1; $x--) {
             for ($y = $top_y; $y < $bottom_y; $y++) {
                 $checkColor = Color::intColorToArrayColor($this->_owner->imageColorAt($x, $y));
                 if ($checkTransparency) {
                     $checkColor['red'] = $color['red'];
                     $checkColor['green'] = $color['green'];
                     $checkColor['blue'] = $color['blue'];
                 }
                 if (Color::differs($color, $checkColor, $this->_tolerance)) {
                     $bottom_x = min($width, $x + 1 + $this->_feather);
                     break 2;
                 }
             }
         }
     }
     $trimmed = new Canvas();
     $trimmed->createImageTrueColorTransparent($bottom_x - $top_x, $bottom_y - $top_y);
     // Preserve transparency
     $transIndex = imagecolortransparent($this->_owner->image);
     if ($transIndex != -1) {
         $rgba = imagecolorsforindex($trimmed->image, $transIndex);
         $transColor = imagecolorallocatealpha($trimmed->image, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
         imagefill($trimmed->image, 0, 0, $transColor);
         imagecolortransparent($trimmed->image, $transColor);
     } else {
         imagealphablending($trimmed->image, false);
         imagesavealpha($trimmed->image, true);
     }
     imagecopyresampled($trimmed->image, $this->_owner->image, 0, 0, $top_x, $top_y, $bottom_x - $top_x, $bottom_y - $top_y, $bottom_x - $top_x, $bottom_y - $top_y);
     $this->_owner->image = $trimmed->image;
     return true;
 }
Ejemplo n.º 7
0
 public function generate()
 {
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     $distance = $this->_distance;
     $matrix = $this->_matrix;
     $matrix_width = count($matrix);
     $matrix_sum = array_sum($matrix);
     $m_offset = floor($matrix_width / 2);
     $temp = new Canvas();
     $temp->createImageTrueColorTransparent($width + $matrix_width * 2, $height + $matrix_width * 2);
     imagecopy($temp->image, $this->_owner->image, $matrix_width, $matrix_width, 0, 0, $width, $height);
     $w = $temp->getImageWidth();
     $h = $temp->getImageHeight();
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             $t = $temp->imagecolorat($x, $y);
             $t1 = Color::intColorToArrayColor($t);
             $p[$x][$y]['r'] = $t1['red'];
             $p[$x][$y]['g'] = $t1['green'];
             $p[$x][$y]['b'] = $t1['blue'];
             $p[$x][$y]['a'] = $t1['alpha'];
             $p1[$x][$y]['r'] = 255;
             $p1[$x][$y]['g'] = 255;
             $p1[$x][$y]['b'] = 255;
             $p1[$x][$y]['a'] = 127;
         }
     }
     $w = $this->_owner->getImageWidth();
     $h = $this->_owner->getImageHeight();
     $d_offset = $distance - $matrix_width;
     if ($this->_color != 'image') {
         $arrColor = Color::hexColorToArrayColor($this->_color);
     }
     $temp->createImageTrueColorTransparent($width + $distance + $m_offset, $height + $distance + $m_offset);
     imagesavealpha($temp->image, true);
     imagealphablending($temp->image, true);
     for ($i = $m_offset; $i < $w + $m_offset + $matrix_width; $i++) {
         for ($j = $m_offset; $j < $h + $m_offset + $matrix_width; $j++) {
             $sumr = 0;
             $sumg = 0;
             $sumb = 0;
             $suma = 0;
             for ($k = 0; $k < $matrix_width; $k++) {
                 $xx = $i - ($matrix_width >> 1) + $k;
                 $sumr += $p[$xx][$j]['r'] * $matrix[$k];
                 $sumg += $p[$xx][$j]['g'] * $matrix[$k];
                 $sumb += $p[$xx][$j]['b'] * $matrix[$k];
                 $suma += $p[$xx][$j]['a'] * $matrix[$k];
             }
             $p1[$i][$j]['r'] = $sumr / $matrix_sum;
             $p1[$i][$j]['g'] = $sumg / $matrix_sum;
             $p1[$i][$j]['b'] = $sumb / $matrix_sum;
             $p1[$i][$j]['a'] = $suma / $matrix_sum;
         }
     }
     for ($i = $m_offset; $i < $w + $m_offset + $matrix_width; $i++) {
         for ($j = $m_offset; $j < $h + $m_offset + $matrix_width; $j++) {
             $sumr = 0;
             $sumg = 0;
             $sumb = 0;
             $suma = 0;
             for ($k = 0; $k < $matrix_width; $k++) {
                 $xy = $j - ($matrix_width >> 1) + $k;
                 $sumr += $p1[$i][$xy]['r'] * $matrix[$k];
                 $sumg += $p1[$i][$xy]['g'] * $matrix[$k];
                 $sumb += $p1[$i][$xy]['b'] * $matrix[$k];
                 $suma += $p1[$i][$xy]['a'] * $matrix[$k];
             }
             if ($this->_color != 'image') {
                 $col = imagecolorallocatealpha($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue'], $suma / $matrix_sum);
             } else {
                 $col = imagecolorallocatealpha($temp->image, $sumr / $matrix_sum, $sumg / $matrix_sum, $sumb / $matrix_sum, $suma / $matrix_sum);
             }
             imagesetpixel($temp->image, $i + $d_offset, $j + $d_offset, $col);
         }
     }
     imagecopy($temp->image, $this->_owner->image, 0, 0, 0, 0, $width, $height);
     $this->_owner->image = $temp->image;
     unset($temp);
     return true;
 }
Ejemplo n.º 8
0
 public function generate()
 {
     imagesavealpha($this->_owner->image, true);
     imagealphablending($this->_owner->image, false);
     $image_x = $this->_owner->getImageWidth();
     $image_y = $this->_owner->getImageHeight();
     $gdCorner = imagecreatefromstring(base64_decode(self::$_cornerpng));
     $corner = new Canvas();
     $corner->createImageTrueColorTransparent($this->_radius_x, $this->_radius_y);
     imagecopyresampled($corner->image, $gdCorner, 0, 0, 0, 0, $this->_radius_x, $this->_radius_y, imagesx($gdCorner), imagesy($gdCorner));
     $corner_x = $this->_radius_x - 1;
     $corner_y = $this->_radius_y - 1;
     for ($y = 0; $y < $corner_y; $y++) {
         for ($x = 0; $x < $corner_x; $x++) {
             for ($c = 0; $c < 4; $c++) {
                 switch ($c) {
                     case 0:
                         $xo = 0;
                         $yo = 0;
                         $cxo = $x;
                         $cyo = $y;
                         break;
                     case 1:
                         $xo = $image_x - $corner_x;
                         $yo = 0;
                         $cxo = $corner_x - $x;
                         $cyo = $y;
                         break;
                     case 2:
                         $xo = $image_x - $corner_x;
                         $yo = $image_y - $corner_y;
                         $cxo = $corner_x - $x;
                         $cyo = $corner_y - $y;
                         break;
                     case 3:
                         $xo = 0;
                         $yo = $image_y - $corner_y;
                         $cxo = $x;
                         $cyo = $corner_y - $y;
                         break;
                 }
                 $irgb = imagecolorat($this->_owner->image, $xo + $x, $yo + $y);
                 $r = $irgb >> 16 & 0xff;
                 $g = $irgb >> 8 & 0xff;
                 $b = $irgb & 0xff;
                 $crgb = imagecolorat($corner->image, $cxo, $cyo);
                 $a = $crgb >> 24 & 0xff;
                 $colour = imagecolorallocatealpha($this->_owner->image, $r, $g, $b, $a);
                 switch ($c) {
                     case 0:
                         imagesetpixel($this->_owner->image, $x, $y, $colour);
                         break;
                     case 1:
                         imagesetpixel($this->_owner->image, $xo + $x, $y, $colour);
                         break;
                     case 2:
                         imagesetpixel($this->_owner->image, $xo + $x, $yo + $y, $colour);
                         break;
                     case 3:
                         imagesetpixel($this->_owner->image, $x, $yo + $y, $colour);
                         break;
                 }
             }
         }
     }
     return true;
 }