Пример #1
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;
 }
Пример #2
0
 public function generate()
 {
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     $mx = array(array(-0, 0, 0), array(-1, 0, 1), array(-0, 0, 0));
     $my = array(array(0, 1, 0), array(0, 0, 0), array(-0, -1, -0));
     $p = array();
     for ($y = 0; $y < $height; $y++) {
         for ($x = 0; $x < $width; $x++) {
             $rgb = $this->_owner->imagecolorat($x, $y);
             $arrRgb = Color::intColorToArrayColor($rgb);
             $p[$x][$y]['r'] = $arrRgb['red'];
             $p[$x][$y]['g'] = $arrRgb['green'];
             $p[$x][$y]['b'] = $arrRgb['blue'];
         }
     }
     for ($y = 1; $y < $height - 1; $y++) {
         for ($x = 1; $x < $width - 1; $x++) {
             $sumXr = $sumXg = $sumXb = $sumYr = $sumYg = $sumYb = 0;
             for ($i = -1; $i <= 1; $i++) {
                 for ($j = -1; $j <= 1; $j++) {
                     $sumXr = $sumXr + $p[$x + $i][$y + $j]['r'] * $mx[$i + 1][$j + 1];
                     $sumXg = $sumXg + $p[$x + $i][$y + $j]['g'] * $mx[$i + 1][$j + 1];
                     $sumXb = $sumXb + $p[$x + $i][$y + $j]['b'] * $mx[$i + 1][$j + 1];
                     $sumYr = $sumYr + $p[$x + $i][$y + $j]['r'] * $my[$i + 1][$j + 1];
                     $sumYg = $sumYg + $p[$x + $i][$y + $j]['g'] * $my[$i + 1][$j + 1];
                     $sumYb = $sumYb + $p[$x + $i][$y + $j]['b'] * $my[$i + 1][$j + 1];
                 }
             }
             $sumr = abs($sumXr) + abs($sumYr);
             $sumg = abs($sumXg) + abs($sumYg);
             $sumb = abs($sumXb) + abs($sumYb);
             if ($sumr > 255) {
                 $sumr = 255;
             }
             if ($sumg > 255) {
                 $sumg = 255;
             }
             if ($sumb > 255) {
                 $sumb = 255;
             }
             if ($sumr < 0) {
                 $sumr = 0;
             }
             if ($sumg < 0) {
                 $sumg = 0;
             }
             if ($sumb < 0) {
                 $sumb = 0;
             }
             $color = imagecolorallocate($this->_owner->image, 255 - $sumr, 255 - $sumg, 255 - $sumb);
             imagesetpixel($this->_owner->image, $x, $y, $color);
         }
     }
     return true;
 }
Пример #3
0
 public function generate()
 {
     $findColor = Color::hexColorToArrayColor($this->_find);
     $replaceColor = Color::hexColorToArrayColor($this->_replace);
     $index = imagecolorclosest($this->_owner->image, $findColor['red'], $findColor['green'], $findColor['blue']);
     //find
     imagecolorset($this->_owner->image, $index, $replaceColor['red'], $replaceColor['green'], $replaceColor['blue']);
     //replace
     unset($index);
     return true;
 }
Пример #4
0
 public function generate()
 {
     $width = $this->_owner->getImageWidth();
     $height = $this->_owner->getImageHeight();
     $padding = $this->_padding;
     $arrColor = Color::hexColorToArrayColor($this->_color);
     $temp = new Canvas();
     $temp->createImageTrueColor($width + $padding * 2, $height + $padding * 2);
     $tempcolor = imagecolorallocate($temp->image, $arrColor['red'], $arrColor['green'], $arrColor['blue']);
     imagefill($temp->image, 0, 0, $tempcolor);
     imagecopy($temp->image, $this->_owner->image, $padding, $padding, 0, 0, $width, $height);
     $this->_owner->image = $temp->image;
     unset($temp);
     return true;
 }
Пример #5
0
 public function generate()
 {
     $alt = 0;
     imagesavealpha($this->_owner->image, true);
     imagealphablending($this->_owner->image, true);
     $color = Color::hexColorToArrayColor($this->_color);
     $light = imagecolorallocatealpha($this->_owner->image, $color['red'], $color['green'], $color['blue'], $this->_light_alpha);
     $dark = imagecolorallocatealpha($this->_owner->image, $color['red'], $color['green'], $color['blue'], $this->_dark_alpha);
     for ($x = 0; $x < $this->_owner->getImageHeight(); $x += $this->_width) {
         if ($alt++ % 2 == 0) {
             imagefilledrectangle($this->_owner->image, 0, $x, $this->_owner->getImageWidth(), $x + $this->_width - 1, $light);
         } else {
             imagefilledrectangle($this->_owner->image, 0, $x, $this->_owner->getImageWidth(), $x + $this->_width - 1, $dark);
         }
     }
     return true;
 }
Пример #6
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;
 }
Пример #7
0
 public function drawFaceRectangle($color = 'FF0000')
 {
     imagerectangle($this->_owner->image, $this->face['x'], $this->face['y'], $this->face['x'] + $this->face['w'], $this->face['y'] + $this->face['w'], Color::hexColorToIntColor($color));
     return $this;
 }
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
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;
 }
Пример #11
0
 private function analyseHsb()
 {
     foreach (array_keys($this->__count_colours) as $color) {
         $arrColor = Color::intColorToArrayColor($color);
         list($h, $s, $b) = $this->hsb($arrColor['red'], $arrColor['green'], $arrColor['blue']);
         @$this->__count_hue[$h]++;
         @$this->__count_saturation[$s]++;
         @$this->__count_brightness[$b]++;
     }
     $this->__analyse_HSB_complete = true;
 }
Пример #12
0
 /**
  * Allocate a color for an image.
  *
  * @param string $color
  * @param int    $alpha
  *
  * @return int
  */
 public function imagecolorallocate($color = 'FFFFFF', $alpha = null)
 {
     if (is_string($color)) {
         $arrColor = Color::hexColorToArrayColor($color);
     } elseif (is_int($color)) {
         $arrColor = Color::intColorToArrayColor($color);
         $alpha = $arrColor['alpha'];
     }
     if ($alpha) {
         return imagecolorallocate($this->image, $arrColor['red'], $arrColor['green'], $arrColor['blue']);
     } else {
         return imagecolorallocatealpha($this->image, $arrColor['red'], $arrColor['green'], $arrColor['blue'], intval($alpha));
     }
 }