public function save($conn = null)
 {
     $return = parent::save($conn);
     if ($this->getObject()->getPath() != '') {
         $uploadDir = sfConfig::get('sf_upload_dir') . '/photo/';
         $image = explode('.', $this->getObject()->getPath());
         $img = new sfImage($uploadDir . $image[0] . '.' . $image[1], swImageTransform::mime_content_type($uploadDir . $image[0] . '.' . $image[1]));
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(780, 518);
         } else {
             $img->resize(344, 518);
         }
         $img->setQuality(95);
         $img->overlay(new sfImage(sfConfig::get('sf_web_dir') . '/images/marcadagua.png', 'image/png'), 'bottom-right');
         $img->saveAs($uploadDir . $this->getObject()->getSlug() . '.' . $image[1]);
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(130, 86);
         } else {
             $img->resize(130, 196);
             $img->crop(0, 55, 130, 86);
         }
         $img->saveAs($uploadDir . 'thumb_' . $this->getObject()->getSlug() . '.' . $image[1]);
         unlink($uploadDir . $image[0] . '.' . $image[1]);
         $this->getObject()->setPath($this->getObject()->getSlug() . '.' . $image[1]);
         $this->getObject()->save();
     }
     return $return;
 }
Beispiel #2
0
 public function save($conn = null)
 {
     $return = parent::save($conn);
     if (!$this->isNew() and count($this->embeddedForms) != 0) {
         $uploadDir = sfConfig::get('sf_upload_dir') . '/gallery/';
         $image = $this->embeddedForms['photo']->getObject()->getPath();
         $img = new sfImage($uploadDir . $image, swImageTransform::mime_content_type($uploadDir . $image));
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(600, null);
         } else {
             $img->resize(null, 480);
         }
         $img->setQuality(95);
         $img->overlay(new sfImage(sfConfig::get('sf_web_dir') . '/images/marcadagua.png', 'image/png'), 'bottom-right');
         $img->save();
         $img->resize(null, 80)->saveAs($uploadDir . 'thumb_' . $image);
     }
     return $return;
 }
 /**
  * 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;
     switch ($this->getMethod()) {
         case 'deflate':
         case 'inflate':
             return $image->resize($this->getWidth(), $this->getHeight());
         case 'left':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop(0, (int) round(($image->getHeight() - $this->getHeight()) / 2), $this->getWidth(), $this->getHeight());
         case 'right':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop($image->getWidth() - $this->getWidth(), (int) round(($image->getHeight() - $this->getHeight()) / 2), $this->getWidth(), $this->getHeight());
         case 'top':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop((int) round(($image->getWidth() - $this->getWidth()) / 2), 0, $this->getWidth(), $this->getHeight());
         case 'bottom':
             $image->scale(max($scale_w, $scale_h));
             return $image->crop((int) round(($image->getWidth() - $this->getWidth()) / 2), $image->getHeight() - $this->getHeight(), $this->getWidth(), $this->getHeight());
         case 'center':
             $image->scale(max($scale_w, $scale_h));
             $left = (int) round(($image->getWidth() - $this->getWidth()) / 2);
             $top = (int) round(($image->getHeight() - $this->getHeight()) / 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;
     }
 }