Esempio n. 1
0
 /**
  * Apply the opacity transformation to the sfImage object
  *
  * @param sfImage
  *
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $new_img = $image->getAdapter()->getTransparentImage($image->getWidth(), $image->getHeight());
     imagealphablending($new_img, false);
     imagesavealpha($new_img, true);
     $opacity = (int) round(127 - 127 / 100 * $this->getOpacity());
     // imagesavealpha($new_img, true);
     $width = $image->getWidth();
     $height = $image->getHeight();
     for ($x = 0; $x < $width; $x++) {
         for ($y = 0; $y < $height; $y++) {
             $rgb = imagecolorat($image->getAdapter()->getHolder(), $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $alpha = ($rgb & 0x7f000000) >> 24;
             $new_opacity = $alpha + (127 - $alpha) / 100 * $this->getOpacity();
             $colors[$alpha] = $new_opacity;
             $color = imagecolorallocatealpha($new_img, $r, $g, $b, $new_opacity);
             imagesetpixel($new_img, $x, $y, $color);
         }
     }
     $image->getAdapter()->setHolder($new_img);
     return $image;
 }
Esempio n. 2
0
 /**
  * Apply the transformation to the image and returns the image thumbnail
  */
 protected function transform(sfImage $image)
 {
     // Work out where we need to draw to
     $offset = $this->getThickness() / 2;
     $mod = $this->getThickness() % 2;
     $x2 = $image->getWidth() - $offset - ($mod === 0 ? 1 : 0);
     $y2 = $image->getHeight() - $offset - ($mod === 0 ? 1 : 0);
     $image->rectangle($offset, $offset, $x2, $y2, $this->getThickness(), $this->getColor());
     return $image;
 }
Esempio n. 3
0
 /**
  * Apply the transformation to the image and returns the image thumbnail
  */
 protected function transform(sfImage $image)
 {
     $resource_w = $image->getWidth();
     $resource_h = $image->getHeight();
     $scale_w = $this->getWidth() / $resource_w;
     $scale_h = $this->getHeight() / $resource_h;
     $method = $this->getMethod();
     switch ($method) {
         case 'deflate':
         case 'inflate':
             return $image->resize($this->getWidth(), $this->getHeight());
         case 'left':
         case 'right':
         case 'top':
         case 'bottom':
         case 'top-left':
         case 'top-right':
         case 'bottom-left':
         case 'bottom-right':
         case 'center':
             $image->scale(max($scale_w, $scale_h));
             if (false !== strstr($method, 'top')) {
                 $top = 0;
             } else {
                 if (false !== strstr($method, 'bottom')) {
                     $top = $image->getHeight() - $this->getHeight();
                 } else {
                     $top = (int) round(($image->getHeight() - $this->getHeight()) / 2);
                 }
             }
             if (false !== strstr($method, 'left')) {
                 $left = 0;
             } else {
                 if (false !== strstr($method, 'right')) {
                     $left = $image->getWidth() - $this->getWidth();
                 } else {
                     $left = (int) round(($image->getWidth() - $this->getWidth()) / 2);
                 }
             }
             return $image->crop($left, $top, $this->getWidth(), $this->getHeight());
         case 'scale':
             return $image->scale(min($scale_w, $scale_h));
         case 'fit':
         default:
             $img = clone $image;
             $image->create($this->getWidth(), $this->getHeight());
             // Set a background color if specified
             if (!is_null($this->getBackground()) && $this->getBackground() != '') {
                 $image->fill(0, 0, $this->getBackground());
             }
             $img->scale(min($this->getWidth() / $img->getWidth(), $this->getHeight() / $img->getHeight()));
             $image->overlay($img, 'center');
             return $image;
     }
 }
Esempio n. 4
0
 protected function transformDefault(sfImage $image)
 {
     $w = $image->getWidth();
     $h = $image->getHeight();
     $resource = $image->getAdapter()->getHolder();
     $mask = $this->getMask()->getAdapter()->getHolder();
     imagealphablending($resource, true);
     $resource_transparent = imagecolorallocate($resource, 0, 0, 0);
     imagecolortransparent($resource, $resource_transparent);
     // Copy $mask over the top of $resource maintaining the Alpha transparency
     imagecopymerge($resource, $mask, 0, 0, 0, 0, $w, $h, 100);
 }
 /**
  * Apply the opacity transformation to the sfImage object
  *
  * @param sfImage
  *
  * @return sfImage
  */
 public function transform(sfImage $image)
 {
     // Get the actual image resource
     $resource = $image->getAdapter()->getHolder();
     //get the resource dimentions
     $width = $image->getWidth();
     $height = $image->getHeight();
     $reflection = $image->copy();
     $reflection->flip()->resize($width, $this->reflection_height);
     $r_resource = $reflection->getAdapter()->getHolder();
     $dest_resource = $reflection->getAdapter()->getTransparentImage($width, $height + $this->reflection_height);
     imagecopymerge($dest_resource, $resource, 0, 0, 0, 0, $width, $height, 100);
     imagecopymerge($dest_resource, $r_resource, 0, $height, 0, 0, $width, $this->reflection_height, 100);
     // Increments we are going to increase the transparency
     $increment = 100 / $this->reflection_height;
     // Overlay line we use to apply the transparency
     $line = imagecreatetruecolor($width, 1);
     // Use white as our overlay color
     imagefilledrectangle($line, 0, 0, $width, 1, imagecolorallocate($line, 255, 255, 255));
     $tr = $this->start_transparency;
     // Start at the bottom of the original image
     for ($i = $height; $i <= $height + $this->reflection_height; $i++) {
         if ($tr > 100) {
             $tr = 100;
         }
         imagecopymerge($dest_resource, $line, 0, $i, 0, 0, $width, 1, $tr);
         $tr += $increment;
     }
     // To set a new resource for the image object
     $image->getAdapter()->setHolder($dest_resource);
     return $image;
 }
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     // Attempt to calibrate the parameters to Photoshop:
     $amount = $this->getAmount() * 0.016;
     $radius = abs(round($this->getRadius() * 2));
     $threshold = $this->getThreshold();
     $w = $image->getWidth();
     $h = $image->getHeight();
     if ($radius > 0) {
         $imgCanvas = imagecreatetruecolor($w, $h);
         $imgBlur = imagecreatetruecolor($w, $h);
         if (function_exists('imageconvolution')) {
             $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1));
             imagecopy($imgBlur, $resource, 0, 0, 0, 0, $w, $h);
             imageconvolution($imgBlur, $matrix, 16, 0);
         } else {
             // Move copies of the image around one pixel at the time and merge them with weight
             // according to the matrix. The same matrix is simply repeated for higher radii.
             for ($i = 0; $i < $radius; $i++) {
                 imagecopy($imgBlur, $resource, 0, 0, 1, 0, $w - 1, $h);
                 // left
                 imagecopymerge($imgBlur, $resource, 1, 0, 0, 0, $w, $h, 50);
                 // right
                 imagecopymerge($imgBlur, $resource, 0, 0, 0, 0, $w, $h, 50);
                 // center
                 imagecopy($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
                 imagecopymerge($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333);
                 // up
                 imagecopymerge($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25);
                 // down
             }
         }
         if ($threshold > 0) {
             // Calculate the difference between the blurred pixels and the original
             // and set the pixels
             // Each row
             for ($x = 0; $x < $w - 1; $x++) {
                 // Each pixel
                 for ($y = 0; $y < $h; $y++) {
                     $rgbOrig = ImageColorAt($resource, $x, $y);
                     $rOrig = $rgbOrig >> 16 & 0xff;
                     $gOrig = $rgbOrig >> 8 & 0xff;
                     $bOrig = $rgbOrig & 0xff;
                     $rgbBlur = ImageColorAt($imgBlur, $x, $y);
                     $rBlur = $rgbBlur >> 16 & 0xff;
                     $gBlur = $rgbBlur >> 8 & 0xff;
                     $bBlur = $rgbBlur & 0xff;
                     // When the masked pixels differ less from the original
                     // than the threshold specifies, they are set to their original value.
                     $rNew = $rOrig;
                     if (abs($rOrig - $rBlur) >= $threshold) {
                         $rNew = max(0, min(255, $amount * ($rOrig - $rBlur) + $rOrig));
                     }
                     $gNew = $gOrig;
                     if (abs($gOrig - $gBlur) >= $threshold) {
                         $gNew = max(0, min(255, $amount * ($gOrig - $gBlur) + $gOrig));
                     }
                     $bNew = $bOrig;
                     if (abs($bOrig - $bBlur) >= $threshold) {
                         $bNew = max(0, min(255, $amount * ($bOrig - $bBlur) + $bOrig));
                     }
                     if ($rOrig != $rNew || $gOrig != $gNew || $bOrig != $bNew) {
                         $pixCol = ImageColorAllocate($resource, $rNew, $gNew, $bNew);
                         ImageSetPixel($resource, $x, $y, $pixCol);
                     }
                 }
             }
         } else {
             // each row
             for ($x = 0; $x < $w; $x++) {
                 // each pixel
                 for ($y = 0; $y < $h; $y++) {
                     $rgbOrig = ImageColorAt($resource, $x, $y);
                     $rOrig = $rgbOrig >> 16 & 0xff;
                     $gOrig = $rgbOrig >> 8 & 0xff;
                     $bOrig = $rgbOrig & 0xff;
                     $rgbBlur = ImageColorAt($imgBlur, $x, $y);
                     $rBlur = $rgbBlur >> 16 & 0xff;
                     $gBlur = $rgbBlur >> 8 & 0xff;
                     $bBlur = $rgbBlur & 0xff;
                     $rNew = $amount * ($rOrig - $rBlur) + $rOrig;
                     if ($rNew > 255) {
                         $rNew = 255;
                     } elseif ($rNew < 0) {
                         $rNew = 0;
                     }
                     $gNew = $amount * ($gOrig - $gBlur) + $gOrig;
                     if ($gNew > 255) {
                         $gNew = 255;
                     } elseif ($gNew < 0) {
                         $gNew = 0;
                     }
                     $bNew = $amount * ($bOrig - $bBlur) + $bOrig;
                     if ($bNew > 255) {
                         $bNew = 255;
                     } elseif ($bNew < 0) {
                         $bNew = 0;
                     }
                     $rgbNew = ($rNew << 16) + ($gNew << 8) + $bNew;
                     ImageSetPixel($resource, $x, $y, $rgbNew);
                 }
             }
         }
         imagedestroy($imgCanvas);
         imagedestroy($imgBlur);
     }
     return $image;
 }
Esempio n. 7
0
 /**
  * Apply the transformation to the image and returns the resized image
  */
 protected function transform(sfImage $image)
 {
     list($target_w, $target_h) = $this->computeTargetSize($image->getWidth(), $image->getHeight());
     return $image->resizeSimple($target_w, $target_h);
 }