예제 #1
0
 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;
 }
예제 #2
0
/**
 * générer le thumb correspondant à une image.
 * cete fonction vérifie si le thumb existe déjà ou si la source est plus récente
 * si besoin, il est regénéré.
 * il faut faire passer en parametres options[width] et options[height]
 * et l'image est automatiquement redimensionner en thumb.
 * si width = height alors l'image sera tronquée et carré
 *
 * @param <string> $image_name : le nom de l'image donc généralement le $object->getImage(), pas de répertoire
 * @param <string> $folder : le nom du r?épertoire dans uploads où est stocké l'image : uploads/object/source => $folder = object
 * @param <array> $options : les parametres à passer à l'image: width et height
 * @param <string> $resize : l'opération sur le thumb: "scale" pour garder les proportions, "center" pour tronquer l'image
 * @param <string> $default : l'image par défaut si image_name n'existe pas
 * @return <image_path>
 */
function doThumb($image_name, $folder, $options = array(), $resize = 'scale', $default = 'default.jpg')
{
    //valeur par défaut si elles ne sont pas définies
    if (!isset($options['width'])) {
        $options['width'] = 50;
    }
    if (!isset($options['height'])) {
        $options['height'] = 50;
    }
    $source_dir = 'uploads/' . $folder . '/';
    $thumb_dir = 'uploads/' . $folder . '/thumb/';
    //le fichier source
    $source = $source_dir . $image_name;
    $exist = sfConfig::get('sf_web_dir') . '/' . $source;
    if (!is_file($exist)) {
        $image_name = $default;
        $source = 'images/' . $image_name;
        // la valeur par défaut
    }
    $new_name = $options['width'] . 'x' . $options['height'] . '_' . $image_name;
    $new_img = $thumb_dir . $new_name;
    // si le thumb n'existe pas ou s'il est plus ancien que le fichier source
    // alors on regénére le thumb
    if (!is_file(sfConfig::get('sf_web_dir') . '/' . $new_img) or filemtime($source) > filemtime($new_img)) {
        $img = new sfImage($source);
        $img->setQuality(100);
        $img->thumbnail($options['width'], $options['height'], $resize)->saveAs($new_img);
    }
    return image_path('/' . $new_img);
}
예제 #3
0
 public function updateObject($values = null)
 {
     $object = parent::updateObject($values);
     if ($av = $object->getAvatar('raw')) {
         $tmp_name = sfConfig::get('sf_upload_dir') . '/avatars/' . $av;
         if (!file_exists($tmp_name)) {
             return $object;
         }
         // Génération miniature 50x50
         $mini = new sfImage($tmp_name);
         $mini->thumbnail(50, 50, 'inflate');
         $mini->setQuality(80);
         $mini->saveAs(sfConfig::get('sf_upload_dir') . '/avatars/50x50/' . $av);
         // Génération miniature 32x32
         $mini = new sfImage($tmp_name);
         $mini->thumbnail(32, 32, 'inflate');
         $mini->setQuality(80);
         $mini->saveAs(sfConfig::get('sf_upload_dir') . '/avatars/32x32/' . $av);
         // Génération miniature 16x16
         $mini = new sfImage($tmp_name);
         $mini->thumbnail(16, 16, 'inflate');
         $mini->setQuality(80);
         $mini->saveAs(sfConfig::get('sf_upload_dir') . '/avatars/16x16/' . $av);
         // On supprime le fichier original
         unlink($tmp_name);
     }
     return $object;
 }
예제 #4
0
파일: Event.class.php 프로젝트: Gula/magic
 public function save(Doctrine_Connection $conn = null)
 {
     $slug = Magic::slugify($this->getTitle());
     if ($this->isNew()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Event')->findOneBySlug($slug);
             if (!$q) {
                 break;
             } else {
                 $slug = Magic::slugify($this->getTitle());
                 $slug .= $i;
             }
         } while ($i);
         $this->setSlug($slug);
     } elseif ($slug != $this->getSlug()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Event')->findOneBySlug($slug);
             if (!$q) {
                 $this->setSlug($slug);
                 break;
             } else {
                 if ($slug == $this->getSlug()) {
                     break;
                 } else {
                     $slug = Magic::slugify($this->getTitle());
                     $slug .= $i;
                 }
             }
         } while ($i);
     }
     if ($this->get('sticky') == 'no') {
         $this->set('sticky', 1000);
     }
     parent::save($conn);
     $config = sfConfig::get('app_sfDoctrineJCroppablePlugin_models');
     $dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $config['Events']['directory'];
     $image = $this->getImageSrc('mugshot', 'original');
     if ($this->getMugshot() != '') {
         $arr_filename = explode('.', $this->getMugshot());
         $filename = $arr_filename[0] . '_original.' . $arr_filename[1];
         $file = $dir . DIRECTORY_SEPARATOR . $filename;
         if (is_file($file)) {
             $dims = array(array('w' => 950, 'h' => 534), array('w' => 720, 'h' => 405), array('w' => 250, 'h' => 141));
             $size = getimagesize($file);
             $img = new sfImage($file, $size['mime']);
             foreach ($dims as $dim) {
                 $img->resize($dim['w'], $dim['h']);
                 $img->setQuality(90);
                 $img->saveAs($dir . '/' . $arr_filename[0] . '_' . $dim['w'] . 'x' . $dim['h'] . '.jpg');
             }
         }
     }
 }
예제 #5
0
파일: Page.class.php 프로젝트: Gula/magic
 public function save(Doctrine_Connection $conn = null)
 {
     $slug = Magic::slugify($this->getTitle());
     if ($this->isNew()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Page')->findOneBySlug($slug);
             if (!$q) {
                 break;
             } else {
                 $slug = Magic::slugify($this->getTitle());
                 $slug .= $i;
             }
         } while ($i);
         $this->setSlug($slug);
     } elseif ($slug != $this->getSlug()) {
         $i = 0;
         do {
             $i++;
             $q = Doctrine::getTable('Page')->findOneBySlug($slug);
             if (!$q) {
                 $this->setSlug($slug);
                 break;
             } else {
                 if ($slug == $this->getSlug()) {
                     break;
                 } else {
                     $slug = Magic::slugify($this->getTitle());
                     $slug .= $i;
                 }
             }
         } while ($i);
     }
     parent::save($conn);
     // generamos thumbnails
     $file = sfConfig::get('sf_upload_dir') . '/pictures/' . $this->getPicture();
     if (is_file($file)) {
         $dims = array(array('w' => 950, 'h' => 534), array('w' => 720, 'h' => 405), array('w' => 250, 'h' => 141), array('w' => 60, 'h' => 60));
         $size = getimagesize($file);
         $img = new sfImage($file, $size['mime']);
         if (!is_dir(sfConfig::get('sf_upload_dir') . '/' . $this->get('id'))) {
             mkdir(sfConfig::get('sf_upload_dir') . '/' . $this->get('id'), 0777);
         }
         foreach ($dims as $dim) {
             $img->thumbnail($dim['w'], $dim['h']);
             $img->setQuality(90);
             $img->saveAs(sfConfig::get('sf_upload_dir') . '/' . $this->get('id') . '/img_' . $this->get('id') . '_' . $dim['w'] . 'x' . $dim['h'] . '.jpg');
         }
     }
 }
예제 #6
0
 /**
  * Cache the image based on the size set in thumbnails.yml
  */
 public function cache()
 {
     $cache_dir = pathinfo($this->cached_path, PATHINFO_DIRNAME);
     //create cache dir if it doesn't exist
     if (!file_exists($cache_dir)) {
         mkdir($cache_dir, 0777, true);
     }
     $size = zsThumbConfigHandler::getSize($this->size);
     //do image transformations
     $new_image = new sfImage($this->orig_path);
     $new_image->thumbnail($size['width'], $size['height'], array_key_exists('method', $size) ? $size['method'] : 'fit');
     if (array_key_exists('quality', $size)) {
         $new_image->setQuality($size['quality']);
     }
     $new_image->saveAs($this->cached_path);
 }
예제 #7
0
 public function save($conn = null)
 {
     $return = parent::save($conn);
     if ($this->getObject()->getPicture() != '') {
         $uploadDir = sfConfig::get('sf_upload_dir') . '/news/';
         $image = $this->getObject()->getPicture();
         $img = new sfImage($uploadDir . $image, swImageTransform::mime_content_type($uploadDir . $image));
         if ($img->getWidth() > $img->getHeight()) {
             $img->resize(480, null);
         } else {
             $img->resize(null, 360);
         }
         $img->setQuality(95);
         $img->save();
         $img->resize(180, 128)->saveAs($uploadDir . 'thumb_' . $image);
     }
     return $return;
 }
예제 #8
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;
 }
예제 #9
0
파일: ThumbHelper.php 프로젝트: ndachez/acb
/** 
 * -------------------------------------------- AVEC WATERMARK --------------------------------------------
 * 
 * Cette function utilise la précédente afin d'afficher directement l'image avec les balises et les options.
 * @param <string> $image_name : le nom de l’image donc généralement le $object->getImage(), pas de répertoire
 * @param <string> $folder : le nom du répertoire dans "uploads" où est stocké l’image 
 * @param <array> $options : les options contenus dans un array() : la taille de l’image (width et height) + la classe, l'id, le alt ... de l'image
 * @param <string> $resize : "scale" pour garder les proportions (deformation de l'image) OU "center" pour tronquer l’image sans la deformer)
 * @param <string> $default : l’image par défaut si $image_name n’existe pas
 * @param <string> $watermark : l'image représentant le watermark à placer dans le dossier "/images"
 * @param <string> $position : la position du watermark sur l'image (format : [de haut en bas]-[de gauche a droite]) : Pour [de haut en bas] : top, middle, bottom / Pour [de gauche à droite] : left, center, right
 * @return <image_path>
 */
function doThumb_resize_watermark($image_name, $folder, $options = array(), $resize = 'center', $default = 'default.jpg', $watermark = 'images/watermark.png', $position = 'middle-center')
{
    $source_dir = 'uploads/' . $folder . '/';
    $thumb_dir = 'uploads/' . $folder . '/thumb/';
    $source = $source_dir . $image_name;
    $exist = sfConfig::get('sf_web_dir') . '/' . $source;
    if (!is_file($exist)) {
        $image_name = $default;
        $source = 'images/' . $image_name;
    }
    //$new_name = $options['width'].'x'.$options['height'].'_'.$image_name;
    $new_name = $options['width'] . '_' . $image_name;
    $new_img = $thumb_dir . $new_name;
    // si le thumb n'existe pas ou s'il est plus ancien que le fichier source, alors on regénére le thumb
    if (!is_file(sfConfig::get('sf_web_dir') . '/' . $new_img) or filemtime($source) > filemtime($new_img)) {
        $img = new sfImage($source);
        $img->setQuality(100);
        $img->resize($options['width'], $options['height'])->overlay(new sfImage($watermark), $position)->saveAs($new_img);
    }
    return image_path('/' . $new_img);
}
예제 #10
0
 /**
  * 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;
     }
 }
 protected function updateRemoteImage($image, Swift_Message $message, $templateName)
 {
     $fileName = dmOs::join(sfConfig::get('sf_web_dir'), 'cache/mail_templates', md5($image->src . $image->width . $image->height) . pathinfo($image->src, PATHINFO_EXTENSION));
     if (!file_exists($fileName)) {
         $imageData = file_get_contents($image->src);
         if (!$imageData) {
             $this->logError($templateName, 'remote', 'image', $image->src);
             $image->src = '';
             return $image;
         } else {
             $sfImage = new sfImage();
             $sfImage->loadString($imageData);
             $width = $sfImage->getWidth();
             $height = $sfImage->getHeight();
             if (isset($image->width) && strpos($image->width, '%') === false) {
                 $width = $image->width;
             }
             if (isset($image->height) && strpos($image->height, '%') === false) {
                 $width = $image->height;
             }
             $sfImage->setQuality(dmConfig::get('image_resize_quality'));
             $sfImage->thumbnail($width, $height, dmConfig::get('image_resize_method'), null);
             $fileSystem = $this->serviceContainer->getService('filesystem');
             if (!file_exists(dirname($fileName))) {
                 $fileSystem->mkdir(dirname($fileName));
             }
             $sfImage->saveAs($fileName);
             chmod($fileName, 0777);
         }
     }
     if (dmConfig::get('mail_template_embed_remote_images_as_attachments', true)) {
         $image->src = $message->embed(Swift_Image::fromPath($fileName));
     } else {
         $image->src = $this->basePath . str_replace(sfConfig::get('sf_web_dir'), '', $fileName);
     }
     return $image;
 }