protected function createMask(sfImage $image, $w, $h)
 {
     // Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask
     $mask = $image->getAdapter()->getTransparentImage($w, $h);
     // Set the masking colours
     if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) {
         $mask_black = imagecolorallocate($mask, 0, 0, 0);
     } else {
         $mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor());
     }
     // Cannot use white as transparent mask if color is set to white
     if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) {
         $mask_transparent = imagecolorallocate($mask, 255, 0, 0);
     } else {
         $mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0));
         $mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']);
     }
     imagecolortransparent($mask, $mask_transparent);
     imagefill($mask, 0, 0, $mask_black);
     // Draw the rounded rectangle for the mask
     $this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent);
     $mask_image = clone $image;
     $mask_image->getAdapter()->setHolder($mask);
     return $mask_image;
 }
Пример #2
0
 protected function transform(sfImage $image)
 {
     switch ($image->getMIMEType()) {
         case 'image/png':
             $this->transformAlpha($image);
             break;
         case 'image/gif':
         case 'image/jpg':
         default:
             $this->transformDefault($image);
     }
     return $image;
 }
Пример #3
0
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $x = imagesx($resource);
     $y = imagesy($resource);
     // If the width or height is not valid then enforce the aspect ratio
     if (!is_numeric($this->width) || $this->width < 1) {
         $this->width = round($x / $y * $this->height);
     } else {
         if (!is_numeric($this->height) || $this->height < 1) {
             $this->height = round($y / $x * $this->width);
         }
     }
     $dest_resource = $image->getAdapter()->getTransparentImage($this->width, $this->height);
     // Preserving transparency for alpha PNGs
     if ($image->getMIMEType() == 'image/png') {
         imagealphablending($dest_resource, false);
         imagesavealpha($dest_resource, true);
     }
     // Finally do our resizing
     imagecopyresampled($dest_resource, $resource, 0, 0, 0, 0, $this->width, $this->height, $x, $y);
     imagedestroy($resource);
     $image->getAdapter()->setHolder($dest_resource);
     return $image;
 }