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


PHP sfImage::saveAs方法代码示例

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


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

 public function save($conn = null)
 {
     parent::save();
     $BASE = sfConfig::get('sf_web_dir') . '/' . $this->WEB_IMAGE;
     $OC = $this->getObject();
     if ($OC instanceof Cicles) {
         $I = $OC->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(100, 100);
             $nom = $OC->getCicleid() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OC->setImatge($nom)->save();
         }
         $P = $OC->getPdf();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $OC->getCicleid() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($P != $nom) {
                 unlink($BASE . $P);
             }
             $OC->setPdf($nom)->save();
         }
     }
 }
开发者ID:nagiro,项目名称:intra,代码行数:28,代码来源:CiclesForm.class.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($conn = null)
 {
     parent::save();
     $OR = $this->getObject();
     if (!is_null($this['Categories']->getValue())) {
         $OR->setCategories(implode('@', $this['Categories']->getValue()));
     }
     $BASE = sfConfig::get('sf_web_dir') . '/' . $this->WEB_IMATGE;
     if ($OR instanceof Activitats) {
         $I = $OR->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(150, 150);
             $nom = $OR->getActivitatid() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OR->setImatge($nom);
         }
         $P = $OR->getPdf();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $OR->getActivitatid() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $P);
             }
             $OR->setPdf($nom);
         }
     }
     $OR->save();
 }
开发者ID:nagiro,项目名称:intra,代码行数:32,代码来源:ActivitatsTextosForm.class.php

示例5: save

 public function save($conn = null)
 {
     parent::save();
     $BASE = $this->URL_IMAGE;
     $ON = $this->getObject();
     if ($ON instanceof Noticies) {
         $I = $ON->getImatge();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(100, 100);
             $nom = $ON->getIdnoticia() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $ON->setImatge($nom)->save();
         }
         $P = $ON->getAdjunt();
         if (!empty($P) && file_exists($BASE . $P)) {
             $nom = $ON->getIdnoticia() . '.pdf';
             rename($BASE . $P, $BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $P);
             }
             $ON->setAdjunt($nom)->save();
         }
     }
 }
开发者ID:nagiro,项目名称:intra,代码行数:28,代码来源:NoticiesForm.class.php

示例6: storeScreenshot

 public function storeScreenshot()
 {
     $path = sfConfig::get('sf_upload_dir') . '/' . sfConfig::get('app_screenshots_path') . '/' . $this->getPluginId() . '/' . $this->getId();
     ForgeToolkit::createRecursiveDirectory($path . '/thumbs/');
     $filename = $this->getFilename();
     try {
         $tmp = tempnam(sys_get_temp_dir(), uniqid($this->getUrl() . time()));
         @copy($this->getUrl(), $tmp);
         if (@file_get_contents($tmp)) {
             $image = new sfImage($tmp);
             $image->saveAs($path . '/' . $filename);
             $image->thumbnail(sfConfig::get('app_screenshots_' . ($this->isPrimary() ? 'primary' : '') . 'width'), sfConfig::get('app_screenshots_' . ($this->isPrimary() ? 'primary' : '') . 'height'), 'center');
             $image->saveAs($path . '/thumbs/' . $filename, 'image/png');
         }
     } catch (sfImageTransformException $e) {
         $this->delete();
     }
 }
开发者ID:nageshwar545,项目名称:PluginsKit,代码行数:18,代码来源:PluginScreenshot.php

示例7: 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

示例8: 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

示例9: saveFile

 protected function saveFile($field, $filename = null, sfValidatedFile $file = null)
 {
     $file_saved = parent::saveFile($field, $filename = null, $file);
     // generate images ?
     if (sfConfig::get('app_sfMooDooGalleryPlugin_generate_images')) {
         $sizes = sfConfig::get('app_sfMooDooGalleryPlugin_image_size');
         $name = explode('.', $file_saved);
         foreach ($sizes as $size) {
             $image_name = sfConfig::get('app_sfMooDooGalleryPlugin_images_dir') . DIRECTORY_SEPARATOR . $name[0] . '_' . $size['width'] . 'x' . $size['height'] . $file->getExtension();
             $img = new sfImage($file, $file->getType());
             $img->resize($size['width'], $size['height']);
             $img->saveAs($image_name);
         }
     }
     return $file_saved;
 }
开发者ID:retrofox,项目名称:sfMooDooGalleryPlugin,代码行数:16,代码来源:PluginMGPhotoForm.class.php

示例10: 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

示例11: transform

 public function transform(sfImage $img)
 {
     $this->directory = dirname($img->getFilename());
     $arr = array_reverse(explode("/", $img->getFilename()));
     $this->fileName = $arr[0];
     $arr2 = explode(".", $this->fileName);
     if (count($arr2) == 1) {
         $this->fileName .= '.png';
     }
     $destDir = '/tmp';
     $ccFile = $destDir . DIRECTORY_SEPARATOR . 'cc_' . $this->fileName;
     $bwFile = $destDir . DIRECTORY_SEPARATOR . 'bw_' . $this->fileName;
     $ccSmallFile = $destDir . DIRECTORY_SEPARATOR . 'cc_s_' . $this->fileName;
     $bwSmallFile = $destDir . DIRECTORY_SEPARATOR . 'bw_s_' . $this->fileName;
     if (!file_exists($destDir)) {
         mkdir($destDir);
     }
     if ($img->getWidth() > IMG_MAX_WIDTH || $img->getHeight() > IMG_MAX_HEIGHT) {
         if ($img->getWidth() > $img->getHeight() * IMG_RATIO) {
             $img->resize(IMG_MAX_WIDTH, null);
         } else {
             $img->resize(null, IMG_MAX_HEIGHT);
         }
     }
     $img->saveAs($ccFile);
     $img->greyscale()->saveAs($bwFile);
     $smallImg = new sfImage($ccFile);
     if ($smallImg->getWidth() > IMG_SMALL_WIDTH || $smallImg->getHeight() > IMG_SMALL_WIDTH) {
         if ($smallImg->getWidth() > $img->getHeight() * IMG_RATIO) {
             $smallImg->resize(null, IMG_MAX_HEIGHT);
         } else {
             $smallImg->resize(IMG_MAX_WIDTH, null);
         }
     }
     if ($smallImg->getWidth() > IMG_SMALL_WIDTH || $smallImg->getHeight() > IMG_SMALL_HEIGHT) {
         if ($smallImg->getWidth() > $smallImg->getHeight() * IMG_RATIO) {
             $smallImg->resize(null, IMG_SMALL_HEIGHT);
         } else {
             $smallImg->resize(IMG_SMALL_WIDTH, null);
         }
     }
     $x1 = ($smallImg->getWidth() - IMG_SMALL_WIDTH) / 2;
     $y1 = ($smallImg->getHeight() - IMG_SMALL_HEIGHT) / 3;
     $smallImg->crop($x1, $y1, IMG_SMALL_WIDTH, IMG_SMALL_HEIGHT)->saveAs($ccSmallFile);
     $smallImg->greyscale()->saveAs($bwSmallFile);
 }
开发者ID:voota,项目名称:voota,代码行数:46,代码来源:sfImageVoota.php

示例12: save

 public function save($conn = null)
 {
     parent::save();
     $OS = $this->getObject();
     $BASE = $this->BASE . $this->WEB_IMATGE;
     if ($OS instanceof Sites) {
         $I = $OS->getLogourl();
         if (!empty($I) && file_exists($BASE . $I)) {
             $img = new sfImage($BASE . $I, 'image/jpg');
             $img->resize(150, 150);
             $nom = $OS->getSiteId() . '.jpg';
             $img->saveAs($BASE . $nom);
             if ($I != $nom) {
                 unlink($BASE . $I);
             }
             $OS->setLogourl($nom);
         }
     }
     $OS->save();
 }
开发者ID:nagiro,项目名称:intra,代码行数:20,代码来源:SitesForm.class.php

示例13: processForm

 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $file = $this->form->getValue('image');
         $image = $this->form->getObject();
         $notice = $image->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';
         try {
             // Image
             $filename = 'app_' . sha1($file->getOriginalName() . rand(1, 100));
             $extension = str_replace('.', '', $file->getOriginalExtension());
             $path = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $filename . '.' . $extension;
             $file->save($path);
             // Thumb
             $img = new sfImage($path, 'image/jpg');
             $img->thumbnail(150, 150);
             $img->saveAs(sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . $filename . '_thumb' . '.' . $extension);
             // Save
             $image->path = $filename . '.' . $extension;
             $image->type = $extension;
             $image->name = $request->getPostParameter('picture[name]');
             $image->description = $request->getPostParameter('picture[description]');
             $image->apartment_id = $request->getPostParameter('picture[apartment_id]');
             $image->save();
         } catch (Doctrine_Validator_Exception $e) {
             $errorStack = $form->getObject()->getErrorStack();
             $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
             foreach ($errorStack as $field => $errors) {
                 $message .= "{$field} (" . implode(", ", $errors) . "), ";
             }
             $message = trim($message, ', ');
             $this->getUser()->setFlash('error', $message);
             return sfView::SUCCESS;
         }
         // $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $picture)));
     } else {
         $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
     }
 }
开发者ID:alifst11,项目名称:symfonybooking,代码行数:39,代码来源:actions.class.php

示例14: save

 /**
  * Saves the uploaded file.
  *
  * This method can throw exceptions if there is a problem when saving the file.
  *
  * If you don't pass a file name, it will be generated by the generateFilename method.
  * This will only work if you have passed a path when initializing this instance.
  *
  * @param  string $file      The file path to save the file
  * @param  int    $fileMode  The octal mode to use for the new file
  * @param  bool   $create    Indicates that we should make the directory before moving the file
  * @param  int    $dirMode   The octal mode to use when creating the directory
  *
  * @return string The filename without the $this->path prefix
  *
  * @throws Exception
  */
 public function save($file = null, $fileMode = 0666, $create = true, $dirMode = 0777)
 {
     if (is_null($file)) {
         $file = $this->generateFilename();
     }
     if ($file[0] != '/' && $file[0] != '\\' && !(strlen($file) > 3 && ctype_alpha($file[0]) && $file[1] == ':' && ($file[2] == '\\' || $file[2] == '/'))) {
         if (is_null($this->path)) {
             throw new RuntimeException('You must give a "path" when you give a relative file name.');
         }
         $file = $this->path . DIRECTORY_SEPARATOR . $file;
     }
     // get our directory path from the destination filename
     $directory = dirname($file);
     if (!is_readable($directory)) {
         if ($create && !@mkdir($directory, $dirMode, true)) {
             // failed to create the directory
             throw new Exception(sprintf('Failed to create file upload directory "%s".', $directory));
         }
         // chmod the directory since it doesn't seem to work on recursive paths
         chmod($directory, $dirMode);
     }
     if (!is_dir($directory)) {
         // the directory path exists but it's not a directory
         throw new Exception(sprintf('File upload path "%s" exists, but is not a directory.', $directory));
     }
     if (!is_writable($directory)) {
         // the directory isn't writable
         throw new Exception(sprintf('File upload path "%s" is not writable.', $directory));
     }
     $img = new sfImage($this->getTempName(), $this->type);
     $img->thumbnail(sfConfig::get('app_configuration_max_person_image_width', 300), sfConfig::get('app_configuration_max_person_image_height', 300));
     // copy the temp file to the destination file
     $img->saveAs($file);
     // chmod our file
     chmod($file, $fileMode);
     $this->savedName = $file;
     return is_null($this->path) ? $file : str_replace($this->path . DIRECTORY_SEPARATOR, '', $file);
 }
开发者ID:nvidela,项目名称:kimkelen,代码行数:55,代码来源:sfCustomValidatedFile.class.php

示例15: opp_sync_politician_image

/**
 * fetch today's news regarding objects monitored by the user
 *
 * @param string $user - OppUser object
 * @return void
 * @author Guglielmo Celata
 */
function opp_sync_politician_image($pol)
{
    $start_time = microtime(true);
    $success = true;
    echo pakeColor::colorize(sprintf('Processing politician %s...', $pol), array('fg' => 'red', 'bold' => true));
    // invoke the remote getPolImage function to grab the images from op_openpolis
    $remote_img_url = sfConfig::get('app_remote_politicians_images_service_url') . '/' . sfConfig::get('app_remote_openpolis_api_key') . '/' . $pol->getId();
    /* debug
      echo pakeColor::colorize(sprintf('Url:  %s...', $remote_img_url), 
                              array('fg' => 'red', 'bold' => true));
      */
    $file = fopen($remote_img_url, "r");
    if (!$file) {
        $err = "unable to open remote file.";
        $success = false;
    }
    $remote_img_str = '';
    while (!feof($file)) {
        $remote_img_str .= fgets($file, 1024);
    }
    fclose($file);
    $images_root = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'parlamentari' . DIRECTORY_SEPARATOR;
    // resizes images and stores them in the FS
    $picture = new sfImage();
    $picture->setMimeType('image/jpeg');
    $picture->loadString($remote_img_str);
    $picture->resize(91, null);
    $picture->saveAs($images_root . 'picture/' . $pol->getId() . '.jpeg', 'image/jpeg');
    $thumb = new sfImage();
    $thumb->setMimeType('image/jpeg');
    $thumb->loadString($remote_img_str);
    $thumb->resize(40, null);
    $thumb->saveAs($images_root . 'thumb/' . $pol->getId() . '.jpeg', 'image/jpeg');
    $execution_time = microtime(true) - $start_time;
    if ($success) {
        echo " ok (";
    } else {
        echo " {$err} (";
    }
    echo pakeColor::colorize(sprintf("%f", $execution_time), array('fg' => 'cyan'));
    echo ")\n";
}
开发者ID:valerio-bozzolan,项目名称:openparlamento,代码行数:49,代码来源:sfPakeOppTasks.php


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