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


PHP ImageInterface::save方法代码示例

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


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

示例1: process

 /**
  * Process command to image source and save to target
  * 
  * @param string $source
  * @param string $target
  * @param string $commands
  * 
  * @return void
  */
 public function process($source, $target, $commands)
 {
     $targetFolder = pathinfo($target, PATHINFO_DIRNAME);
     if (!file_exists($targetFolder)) {
         mkdir($targetFolder, 0777, true);
     }
     $this->image = $this->getImagineService()->open($source);
     foreach ($this->analyseCommands($commands) as $command) {
         if ($this->runCommand($command)) {
             continue;
         }
         $this->runCustomCommand($command);
     }
     $this->image->save($target);
 }
开发者ID:dgram,项目名称:zf2-imageresizer,代码行数:24,代码来源:ImageProcessing.php

示例2: createFromImagine

 /**
  * @param ImageInterface $image
  * @param $namespace
  * @param $image_hash
  * @param $image_thumb
  * @return File
  */
 public function createFromImagine(ImageInterface $image, $namespace, $image_hash, $image_thumb)
 {
     umask(00);
     $dest = $this->createDestinationPath($namespace, $image_hash, $image_thumb);
     $image->save($dest);
     return new File($dest);
 }
开发者ID:vlatosev,项目名称:filebundle,代码行数:14,代码来源:ImageCacheManager.php

示例3: _autoGuessImageQuality

 /**
  * @param     $tempFileName
  * @param     $originalSize
  * @param     $extension
  * @param     $minQuality
  * @param     $maxQuality
  * @param int $step
  *
  * @return string $path the resulting file path
  */
 private function _autoGuessImageQuality($tempFileName, $originalSize, $extension, $minQuality, $maxQuality, $step = 0)
 {
     // Give ourselves some extra time.
     @set_time_limit(30);
     if ($step == 0) {
         $tempFileName = IOHelper::getFolderName($tempFileName) . IOHelper::getFileName($tempFileName, false) . '-temp.' . $extension;
     }
     // Find our target quality by splitting the min and max qualities
     $midQuality = (int) ceil($minQuality + ($maxQuality - $minQuality) / 2);
     // Set the min and max acceptable ranges. .10 means anything between 90% and 110% of the original file size is acceptable.
     $acceptableRange = 0.1;
     clearstatcache();
     // Generate a new temp image and get it's file size.
     $this->_image->save($tempFileName, $this->_getSaveOptions($midQuality, $extension));
     $newFileSize = IOHelper::getFileSize($tempFileName);
     // If we're on step 10 OR we're within our acceptable range threshold OR midQuality = maxQuality (1 == 1),
     // let's use the current image.
     if ($step == 10 || abs(1 - $originalSize / $newFileSize) < $acceptableRange || $midQuality == $maxQuality) {
         clearstatcache();
         // Generate one last time.
         $this->_image->save($tempFileName, $this->_getSaveOptions($midQuality));
         return $tempFileName;
     }
     $step++;
     if ($newFileSize > $originalSize) {
         return $this->_autoGuessImageQuality($tempFileName, $originalSize, $extension, $minQuality, $midQuality, $step);
     } else {
         return $this->_autoGuessImageQuality($tempFileName, $originalSize, $extension, $midQuality, $maxQuality, $step);
     }
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:40,代码来源:Image.php

示例4: save

 /**
  * Save image to file
  * @param $filePath
  * @param array $options
  * @return $this
  */
 public function save($filePath, $options = [])
 {
     if ($this->image) {
         $this->image->save($filePath, $options);
     }
     return $this;
 }
开发者ID:maddoger,项目名称:yii2-imagecache,代码行数:13,代码来源:Image.php

示例5: createCache

 /**
  * {@inheritDoc}
  */
 public function createCache($relativeName, $filter, ImageInterface $image, $formatOrImage = null, array $saveOptions = [])
 {
     $cachePath = $this->getCachePath($relativeName, $filter, $formatOrImage);
     if (!is_dir(dirname($cachePath))) {
         mkdir(dirname($cachePath), 0755, true);
     }
     $image->save($cachePath, $saveOptions);
 }
开发者ID:shitikovkirill,项目名称:zend-shop.com,代码行数:11,代码来源:CacheManager.php

示例6: cache

 public function cache($path, $format, ImageInterface $data)
 {
     $path = $this->getFullPath($path);
     $this->_prepareDirectoryForFile($path);
     if ($format == "webp") {
         $data->save($path, ["quality" => 100, "format" => "png"]);
         $cwebp = new Cwebp();
         try {
             $cwebp->filter($path);
         } catch (Exception $e) {
             unlink($path);
             throw new RuntimeException($e->getMessage());
         }
     } else {
         $data->save($path, ["quality" => 100, "format" => $format]);
     }
     chmod($path, 0777);
 }
开发者ID:gsouf,项目名称:thumbz,代码行数:18,代码来源:FileCache.php

示例7: process404

 /**
  * Process command to create 404 image and save to target
  * 
  * @param string $target
  * @param string $commands
  * 
  * @return void
  */
 public function process404($target, $commands)
 {
     if (file_exists($target)) {
         return;
     }
     $targetFolder = pathinfo($target, PATHINFO_DIRNAME);
     if (!file_exists($targetFolder)) {
         mkdir($targetFolder, 0777, true);
     }
     $text = 'Not found';
     $backgroundColor = null;
     $color = null;
     $width = null;
     $height = null;
     foreach ($this->analyseCommands($commands) as $command) {
         if ('thumb' === $command['command'] || 'resize' === $command['command']) {
             $width = $command['params'][0];
             $height = $command['params'][1];
         } elseif ('404' === $command['command']) {
             if (isset($command['params'][0]) && UrlSafeBase64::valid($command['params'][0])) {
                 $text = UrlSafeBase64::decode($command['params'][0]);
             }
             if (isset($command['params'][1])) {
                 $backgroundColor = $command['params'][1];
             }
             if (isset($command['params'][2])) {
                 $color = $command['params'][2];
             }
             if (isset($command['params'][3])) {
                 $width = $command['params'][3];
             }
             if (isset($command['params'][4])) {
                 $height = $command['params'][4];
             }
         }
     }
     $this->image404($text, $backgroundColor, $color, $width, $height);
     $this->image->save($target);
 }
开发者ID:tck,项目名称:zf2-imageresizer,代码行数:47,代码来源:ImageProcessing.php

示例8: filterDump

 public function filterDump(ImageInterface $image)
 {
     $pb = $this->createProcessBuilder(array('' . $this->facedetectBin));
     $uniq = uniqid();
     $input = sys_get_temp_dir() . '/evathumber_facedetect_' . $uniq . '_in.png';
     $pb->add($input);
     $image->save($input);
     $output = sys_get_temp_dir() . '/evathumber_facedetect_' . $uniq . '_out.json';
     $pb->add($output);
     $pb->add($this->cascade);
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 < $code) {
         //unlink($input);
         //return false;
     }
     $res = array();
     if (file_exists($output)) {
         $res = json_decode(file_get_contents($output));
         @unlink($output);
     }
     @unlink($input);
     return $res;
 }
开发者ID:yangwu,项目名称:EvaThumber,代码行数:24,代码来源:FaceDetect.php

示例9: saveCachedImage

 /**
  * Saves a cached image preset.
  * @param ImageInterface $image the image.
  * @param string $path the save path (relative to the preset cache path).
  * @param string $filename the filename.
  * @param array $options the options for saving the image.
  * @return ImageInterface the image.
  */
 public function saveCachedImage(ImageInterface $image, $path, $filename, $options = array())
 {
     $path = $this->resolveCachePath() . '/' . $path;
     $this->getManager()->getFileManager()->createDirectory($path);
     return $image->save($path . '/' . $filename, $options);
 }
开发者ID:crisu83,项目名称:yii-imagemanager,代码行数:14,代码来源:ImagePreset.php

示例10: filterDump

 public function filterDump(ImageInterface $image)
 {
     $pb = $this->createProcessBuilder([$this->pngoutBin]);
     if (null !== $this->color) {
         $pb->add('-c' . $this->color);
     }
     if (null !== $this->filter) {
         $pb->add('-f' . $this->filter);
     }
     if (null !== $this->strategy) {
         $pb->add('-s' . $this->strategy);
     }
     if (null !== $this->blockSplitThreshold) {
         $pb->add('-b' . $this->blockSplitThreshold);
     }
     //EvaThumber changes:
     $uniq = uniqid();
     $input = sys_get_temp_dir() . '/evathumber_pngout_' . $uniq . '_in.png';
     $pb->add($input);
     $image->save($input);
     $output = sys_get_temp_dir() . '/evathumber_pngout_' . $uniq . '_out.png';
     $pb->add($output);
     $proc = $pb->getProcess();
     $code = $proc->run();
     if (0 < $code) {
         unlink($input);
         return false;
         //return $image;
     }
     unlink($input);
     return $output;
     $imageClass = explode('\\', get_class($image));
     $imageClass[2] = 'Imagine';
     $imagineClass = implode('\\', $imageClass);
     $imagine = new $imagineClass();
     $image = $imagine->load(file_get_contents($output));
     unlink($input);
     unlink($output);
     return $image;
 }
开发者ID:imvkmark,项目名称:l5-thumber,代码行数:40,代码来源:Pngout.php

示例11: save

 /**
  * Save image
  * @return ImageInterface
  */
 public function save()
 {
     if (file_exists($this->_pathObjectFile)) {
         $this->_url = $this->_urlObjectFile;
         return true;
     } elseif (file_exists($this->_pathObjectFileOrigin)) {
         $this->_image = Image::getImagine()->open($this->_pathObjectFileOrigin);
     } elseif (file_exists($this->_pathObjectPlaceholder)) {
         $this->_url = $this->_urlObjectPlaceholder;
         return true;
     } elseif (file_exists($this->_pathObjectPlaceholderOrigin)) {
         $this->_image = Image::getImagine()->open($this->_pathObjectPlaceholderOrigin);
         $this->_pathObjectFile = $this->_pathObjectPlaceholder;
         $this->_urlObjectFile = $this->_urlObjectPlaceholder;
     } elseif (file_exists($this->_pathRootPlaceholder)) {
         $this->_url = $this->_urlRootPlaceholder;
         return true;
     } elseif (file_exists($this->_pathRootPlaceholderOrigin)) {
         $this->_image = Image::getImagine()->open($this->_pathRootPlaceholderOrigin);
         $this->_pathObjectFile = $this->_pathRootPlaceholder;
         $this->_urlObjectFile = $this->_urlRootPlaceholder;
     }
     if ($this->_image) {
         if (!$this->width || !$this->height) {
             $ratio = $this->_image->getSize()->getWidth() / $this->_image->getSize()->getHeight();
             if ($this->width) {
                 $this->height = ceil($this->width / $ratio);
             } else {
                 $this->width = ceil($this->height * $ratio);
             }
             $box = new Box($this->width, $this->height);
             $this->_image->resize($box);
             $this->_image->crop(new Point(0, 0), $box);
         } else {
             $box = new Box($this->width, $this->height);
             $size = $this->_image->getSize();
             if ($size->getWidth() <= $box->getWidth() && $size->getHeight() <= $box->getHeight() || !$box->getWidth() && !$box->getHeight()) {
             } else {
                 $this->_image = $this->_image->thumbnail($box, ManipulatorInterface::THUMBNAIL_OUTBOUND);
                 // calculate points
                 $size = $this->_image->getSize();
                 $startX = 0;
                 $startY = 0;
                 if ($size->getWidth() < $this->width) {
                     $startX = ceil($this->width - $size->getWidth()) / 2;
                 }
                 if ($size->getHeight() < $this->height) {
                     $startY = ceil($this->height - $size->getHeight()) / 2;
                 }
                 // create empty image to preserve aspect ratio of thumbnail
                 $thumb = Image::getImagine()->create($box, new Color('FFF', 100));
                 $thumb->paste($this->_image, new Point($startX, $startY));
                 $this->_image = $thumb;
             }
         }
         $this->_image->save($this->_pathObjectFile);
         $this->_url = $this->_urlObjectFile;
         return true;
     }
     return false;
 }
开发者ID:beowulfenator,项目名称:yii2-dynamic-image,代码行数:65,代码来源:ImageIndexForm.php

示例12: apply

 /**
  * {@inheritdoc}
  */
 public function apply(ImageInterface $image)
 {
     return $image->save($this->path, $this->options);
 }
开发者ID:noorafree,项目名称:makmakan,代码行数:7,代码来源:Save.php

示例13: saveImage

 /**
  * Save Image to a file
  *
  * @param ImageInterface        $image
  * @param string                $to
  * @param string|ImageInterface $source
  * @param array                 $options
  *
  * @return bool|ImageInterface
  */
 protected function saveImage(ImageInterface $image, $to, $source = '', array $options = array())
 {
     if (!$to && $source && !$source instanceof ImageInterface) {
         $to = $source;
     }
     if ($to) {
         $result = true;
         if ($this->getOption('auto_mkdir') && !$this->mkdir($to)) {
             $result = false;
         } else {
             try {
                 $image->save($to, $options);
             } catch (\Excetpion $e) {
                 $result = false;
             }
         }
     } else {
         $result = $image;
     }
     return $result;
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:31,代码来源:Image.php

示例14: save

 /**
  * Saves the image sprite and stylesheet.
  *
  * @param  Configuration  $config The Configuration instance
  * @param  ImageInterface $image  The ImageInterface instance
  * @param  string         $styles The CSS stylesheet
  * @return void
  *
  * @throws \RuntimeException If the image sprite could not be saved
  * @throws \RuntimeException If the stylesheet could not be saved
  */
 protected function save(Configuration $config, ImageInterface $image, $styles)
 {
     $this->createDirectory(array($config->getImage(), $config->getStylesheet()));
     try {
         $image->save($config->getImage(), $config->getOptions());
     } catch (\RuntimeException $e) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to write file "%s".', $config->getImage()));
         // @codeCoverageIgnoreEnd
     }
     if (false === @file_put_contents($config->getStylesheet(), $styles)) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException(sprintf('Unable to write file "%s".', $config->getStylesheet()));
         // @codeCoverageIgnoreEnd
     }
 }
开发者ID:fermio,项目名称:sprites,代码行数:27,代码来源:AbstractProcessor.php

示例15: createMarkedFile

 /**
  * @param \Imagine\Image\ImageInterface $Image
  * @param string $mark
  */
 private function createMarkedFile(ImageInterface $Image, $mark)
 {
     \Yii::beginProfile('create cache file:' . $this->File->id, __METHOD__);
     list($mark_file_path, $mark_file_web_path) = $this->getMarkedFilePath($mark);
     $mark_dir_path = dirname($mark_file_path);
     if (!file_exists($mark_dir_path) || !is_dir($mark_dir_path)) {
         FileHelper::createDirectory($mark_dir_path);
     }
     $Image->save($mark_file_path, ['quality' => 90]);
     @chmod($mark_file_path, 0664);
     \Yii::endProfile('create cache file:' . $this->File->id, __METHOD__);
 }
开发者ID:rmrevin,项目名称:yii2-file,代码行数:16,代码来源:ImageWrapper.php


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