当前位置: 首页>>代码示例>>PHP>>正文


PHP sfImage::setQuality方法代码示例

本文整理汇总了PHP中sfImage::setQuality方法的典型用法代码示例。如果您正苦于以下问题:PHP sfImage::setQuality方法的具体用法?PHP sfImage::setQuality怎么用?PHP sfImage::setQuality使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfImage的用法示例。


在下文中一共展示了sfImage::setQuality方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 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;
 }
开发者ID:kidh0,项目名称:tiagotrespach,代码行数:28,代码来源:PhotoForm.class.php

示例2: doThumb

/**
 * 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);
}
开发者ID:ndachez,项目名称:emach,代码行数:45,代码来源:ThumbHelper.php

示例3: updateObject

 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;
 }
开发者ID:thefkboss,项目名称:ZenTracker,代码行数:28,代码来源:Avatar.class.php

示例4: save

 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');
             }
         }
     }
 }
开发者ID:Gula,项目名称:magic,代码行数:57,代码来源:Event.class.php

示例5: save

 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');
         }
     }
 }
开发者ID:Gula,项目名称:magic,代码行数:51,代码来源:Page.class.php

示例6: cache

 /**
  * 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);
 }
开发者ID:kbond,项目名称:zsUtilPlugin,代码行数:19,代码来源:zsThumb.class.php

示例7: save

 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;
 }
开发者ID:kidh0,项目名称:swbrasil,代码行数:18,代码来源:NewsForm.class.php

示例8: save

 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;
 }
开发者ID:kidh0,项目名称:swbrasil,代码行数:19,代码来源:GalleryForm.class.php

示例9: doThumb_resize_watermark

/** 
 * -------------------------------------------- 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);
}
开发者ID:ndachez,项目名称:acb,代码行数:34,代码来源:ThumbHelper.php

示例10: importFavicon

 /**
  * 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;
     }
 }
开发者ID:42medien,项目名称:spreadly,代码行数:38,代码来源:ImageImporter.class.php

示例11: updateRemoteImage

 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;
 }
开发者ID:runopencode,项目名称:diem-extended,代码行数:37,代码来源:dmMailTemplateRenderer.php


注:本文中的sfImage::setQuality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。