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;
 }
 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;
 }
 /**
  * saves the favicon of a communitiy
  *
  * @author Matthias Pfefferle
  *
  * @param Object $pCommunity
  * @return boolean true|false
  */
 public static function importFavicon($pCommunity, $pPath = self::PATH_TYPE_URL)
 {
     try {
         // try to get an image from websnapr
         $lImage = UrlUtils::getUrlContent($pCommunity->getFavicon());
         $lBasePath = DIRECTORY_SEPARATOR . 'favicons' . DIRECTORY_SEPARATOR . $pCommunity->getSlug() . '.png';
         // create folder structure and save the image to our local filesystem
         $path = sfConfig::get('sf_upload_dir') . $lBasePath;
         $fp = fopen($path, 'w+');
         fputs($fp, $lImage);
         fclose($fp);
         // get mime-type
         $lImgData = GetImageSize($path);
         if ($lImgData['mime'] != "image/png") {
             $lImg = new sfImage($path, $lImgData['mime'], 'GD');
             $lImg->getMIMEType();
             $lImg->setQuality(100);
             $lImg->saveAs($path, 'image/png');
         }
         unset($lImage);
         if ($pPath == self::PATH_TYPE_URL) {
             return DIRECTORY_SEPARATOR . sfConfig::get('sf_upload_dir_name') . $lBasePath;
         } else {
             return $path;
         }
     } catch (Exception $e) {
         sfContext::getInstance()->getLogger()->err("{ImageImporter} Exception: " . print_r($e, true));
         return null;
     }
 }
 /**
  * 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;
 }