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


PHP Gd\Imagine类代码示例

本文整理汇总了PHP中Imagine\Gd\Imagine的典型用法代码示例。如果您正苦于以下问题:PHP Imagine类的具体用法?PHP Imagine怎么用?PHP Imagine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: handle

 protected function handle()
 {
     $request = $this->getRequest();
     $posts = $request->request;
     $file_path = $posts->get('image_path');
     $x = $posts->get('x');
     $y = $posts->get('y');
     $w = $posts->get('w');
     $h = $posts->get('h');
     $path_info = pathinfo($file_path);
     $imagine = new Imagine();
     $raw_image = $imagine->open($file_path);
     $large_image = $raw_image->copy();
     $large_image->crop(new Point($x, $y), new Box($w, $h));
     $large_file_path = "{$path_info['dirname']}/{$path_info['filename']}_large.{$path_info['extension']}";
     $large_image->save($large_file_path, array('quality' => 70));
     $origin_dir_name = $path_info['dirname'];
     $new_directory = str_replace('/tmp', '', $origin_dir_name);
     $new_file = new File($large_file_path);
     $new_file->move($new_directory, "{$path_info['filename']}.{$path_info['extension']}");
     $container = $this->getContainer();
     $cdn_url = $container->getParameter('cdn_url');
     $new_uri = $cdn_url . '/upload/' . $path_info['filename'] . '.' . $path_info['extension'];
     @unlink($large_file_path);
     @unlink($file_path);
     return new JsonResponse(array('picture_uri' => $new_uri));
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:27,代码来源:ActionIconCrop.php

示例2: resize

 /**
  * {@inheritdoc}
  */
 public function resize($imagePath, array $size, $mode, $force = false)
 {
     $cacheKey = $this->getCacheKey($size, $mode);
     $filename = basename($imagePath);
     if (false === $force && $this->imageCache->contains($filename, $cacheKey)) {
         return $this->imageCache->getRelativePath($filename, $cacheKey);
     }
     $cacheAbsolutePath = $this->imageCache->getAbsolutePath($filename, $cacheKey);
     $imagine = new Imagine();
     $imagineImage = $imagine->open($this->filesystem->getRootDir() . $imagePath);
     $imageSize = array($imagineImage->getSize()->getWidth(), $imagineImage->getSize()->getHeight());
     $boxSize = $this->resizeHelper->getBoxSize($imageSize, $size);
     $box = $this->getBox($boxSize[0], $boxSize[1]);
     if (ImageResizerInterface::INSET === $mode) {
         $imageSizeInBox = $this->resizeHelper->getImageSizeInBox($imageSize, $boxSize);
         $imagineImage->resize($this->getBox($imageSizeInBox[0], $imageSizeInBox[1]));
         $palette = new RGB();
         $box = $imagine->create($box, $palette->color($this->color, $this->alpha));
         $imagineImage = $box->paste($imagineImage, $this->getPointInBox($imageSizeInBox, $boxSize));
     } else {
         $imagineImage = $imagineImage->thumbnail($box);
     }
     $this->filesystem->mkdir(dirname($cacheAbsolutePath));
     $imagineImage->save($cacheAbsolutePath, ImageOptionHelper::getOption($filename));
     return $this->imageCache->getRelativePath($filename, $cacheKey);
 }
开发者ID:silvestra,项目名称:media,代码行数:29,代码来源:GdImageResizer.php

示例3: postSave

 /**
  * @param Picture $picture
  * @param array $data
  */
 protected function postSave(Picture $picture, array $data)
 {
     if (isset($data['meta']) && isset($data['meta']['filename'])) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         $file = new File($module->getUploadPath()->append($data['meta']['filename']));
         $slugifier = new Slugify();
         $filename = sprintf('%s-%u.%s', $slugifier->slugify($picture->getAthlete()), $picture->getId(), $file->getExtension());
         $filepath = $module->getPicturesPath($picture->getSkill())->append($filename);
         $file->move($filepath);
         // create thumb folder
         $thumbspath = $module->getPicturesPath($picture->getSkill())->append('thumbs');
         $dir = new Directory($thumbspath);
         if (!$dir->exists()) {
             $dir->make();
         }
         // create thumb
         $imagine = new Imagine();
         $image = $imagine->open($filepath->toString());
         $max = max($image->getSize()->getWidth(), $image->getSize()->getHeight());
         $width = $image->getSize()->getWidth() / $max * self::THUMB_MAX_SIZE;
         $height = $image->getSize()->getHeight() / $max * self::THUMB_MAX_SIZE;
         $size = new Box($width, $height);
         $thumbpath = $thumbspath->append($filename);
         $image->thumbnail($size)->save($thumbpath->toString());
         // save to picture
         $picture->setUrl($module->getPicturesUrl($picture->getSkill()) . '/' . $filename);
         $picture->setThumbUrl($module->getPicturesUrl($picture->getSkill()) . '/thumbs/' . $filename);
         $picture->save();
     }
     // activity
     $user = $this->getServiceContainer()->getAuthManager()->getUser();
     $user->newActivity(array('verb' => $this->isNew ? Activity::VERB_UPLOAD : Activity::VERB_EDIT, 'object' => $picture, 'target' => $picture->getSkill()));
 }
开发者ID:gossi,项目名称:trixionary,代码行数:37,代码来源:PictureDomain.php

示例4: save

 public function save()
 {
     $model = Books::findOne($this->id);
     $fileInstance = UploadedFile::getInstance($this, self::FIELD_PREVIEW);
     if ($fileInstance) {
         $filePath = 'images/' . $fileInstance->baseName . '.' . $fileInstance->extension;
         $model->preview = $fileInstance->baseName . '.' . $fileInstance->extension;
         $fileInstance->saveAs($filePath, false);
         $imagine = new Gd\Imagine();
         try {
             $filePath = 'images/preview_' . $fileInstance->baseName . '.' . $fileInstance->extension;
             $img = $imagine->open($fileInstance->tempName);
             $size = $img->getSize();
             if ($size->getHeight() > $this->imageSizeLimit['width'] || $size->getWidth() > $this->imageSizeLimit['height']) {
                 $img->resize(new Box($this->imageSizeLimit['width'], $this->imageSizeLimit['height']));
             }
             $img->save($filePath);
             //
         } catch (\Imagine\Exception\RuntimeException $ex) {
             $this->addError(self::FIELD_PREVIEW, 'Imagine runtime exception: ' . $ex->getMessage());
             return FALSE;
         }
     }
     if (!$this->validate()) {
         return false;
     }
     $model->name = $this->name;
     $model->author_id = $this->author_id;
     $model->date = DateTime::createFromFormat('d/m/Y', $this->date)->format('Y-m-d');
     $model->date_update = new Expression('NOW()');
     $model->save();
     return true;
 }
开发者ID:andreyshade,项目名称:test_yii2,代码行数:33,代码来源:BooksForm.php

示例5: postSave

 /**
  * @param Sport $sport
  * @param array $data
  */
 protected function postSave(Sport $sport, array $data)
 {
     // upload picture
     if (isset($data['meta']) && isset($data['meta']['filename']) && !empty($data['meta']['filename'])) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         // ensure directory
         $dir = new Directory($module->getSportPath($sport));
         if (!$dir->exists()) {
             $dir->make();
         }
         $destpath = $module->getSkillPreviewPath($sport);
         $dest = new File($destpath);
         if ($dest->exists()) {
             $dest->delete();
         }
         $file = new File($module->getUploadPath()->append($data['meta']['filename']));
         $imagine = new Imagine();
         $image = $imagine->open($file->toPath()->toString());
         $image->save($dest->toPath()->toString());
         $file->delete();
         $sport->setSkillPictureUrl($module->getSkillPreviewUrl($sport));
         $sport->save();
     }
     // delete picture
     if (isset($data['meta']) && isset($data['meta']['skill_picture_delete']) && $data['meta']['skill_picture_delete'] == 1) {
         $module = $this->getServiceContainer()->getModuleManager()->load('gossi/trixionary');
         $path = $module->getSkillPreviewPath($sport);
         $file = new File($path);
         $file->delete();
         $sport->setSkillPictureUrl(null);
         $sport->save();
     }
 }
开发者ID:gossi,项目名称:trixionary,代码行数:37,代码来源:SportDomain.php

示例6: testGetExceptionWithInvalidWatermarkSize

 public function testGetExceptionWithInvalidWatermarkSize()
 {
     $this->setExpectedException('HtImgModule\\Exception\\InvalidArgumentException');
     $imagine = new Imagine();
     $archos = $imagine->open('resources/Archos.jpg');
     $watermark = new Watermark($archos, 'asfd', 'asdf');
 }
开发者ID:shitikovkirill,项目名称:zend-shop.com,代码行数:7,代码来源:WatermarkTest.php

示例7: doFilter

 /**
  * Turn an image Negative
  *
  * @param string $file
  * @param array $arguments
  * @param array $typeOptions
  *
  * @return void
  */
 public function doFilter($file, $arguments, $typeOptions)
 {
     $Imagine = new Imagine();
     $image = $Imagine->open($file);
     $image->effects()->negative();
     $image->save($file);
 }
开发者ID:is00hcw,项目名称:munee,代码行数:16,代码来源:Negative.php

示例8: toThumbnail

 /**
  * @param     $img
  * @param int $width
  * @param int $height
  * @return \Imagine\Image\ManipulatorInterface
  */
 public function toThumbnail($img, $width = 120, $height = 120)
 {
     $thumbnail = pathinfo($img, PATHINFO_DIRNAME) . '/' . pathinfo($img, PATHINFO_FILENAME) . '_thumbnil.' . pathinfo($img, PATHINFO_EXTENSION);
     $imagine = new Imagine();
     $imagine->open($img)->thumbnail(new Box($width, $height), ImageInterface::THUMBNAIL_OUTBOUND)->save($thumbnail);
     return $thumbnail;
 }
开发者ID:JanHuang,项目名称:media-bundle,代码行数:13,代码来源:Uploader.php

示例9: actionIndex

 public function actionIndex($type = null, $size = null, $pictureFilename = null, $extension = null)
 {
     try {
         ini_set('memory_limit', '1024M');
         error_reporting(1);
         list($x, $y) = explode('x', $size);
         $imagine = new Imagine();
         $picture = $imagine->open(\Yii::$app->basePath . '/web/pictures/' . $type . '/full_size/' . $pictureFilename . '.' . $extension);
         $pictureSize = $picture->getSize();
         $pictureWidth = $pictureSize->getWidth();
         $pictureHeight = $pictureSize->getHeight();
         if (!$x) {
             $aspectRatio = $pictureWidth / $pictureHeight;
         } elseif (!$y) {
             $aspectRatio = $pictureHeight / $pictureWidth;
         }
         $y = $y ? $y : round($aspectRatio * $x);
         $x = $x ? $x : round($aspectRatio * $y);
         $box = new Box($x, $y, ImageInterface::FILTER_UNDEFINED);
         $mode = ImageInterface::THUMBNAIL_OUTBOUND;
         $thumbnail = $picture->thumbnail($box, $mode);
         $thumbnailSize = $thumbnail->getSize();
         $thumbnailX = $thumbnailSize->getWidth();
         $xPos = $x / 2 - $thumbnailX / 2;
         $color = $extension == 'png' ? new Color('#fff', 100) : new Color('#fff');
         $imagine->create($box, $color)->paste($thumbnail, new Point($xPos, 0))->save(\Yii::$app->basePath . '/web/pictures/' . $type . '/' . $size . '/' . $pictureFilename . '.' . $extension)->show($extension);
     } catch (Exception $e) {
         return false;
     }
 }
开发者ID:pbabilas,项目名称:bcode,代码行数:30,代码来源:CreateController.php

示例10: upload

 public function upload($width = 593, $height = 393)
 {
     // la propriété « file » peut être vide si le champ n'est pas requis
     if (null === $this->file) {
         return;
     }
     // utilisez le nom de fichier original ici mais
     // vous devriez « l'assainir » pour au moins éviter
     // quelconques problèmes de sécurité
     // la méthode « move » prend comme arguments le répertoire cible et
     // le nom de fichier cible où le fichier doit être déplacé
     $clean_file = $this->slugify($this->file->getClientOriginalName());
     $clean_file = str_replace($this->file->guessClientExtension(), "", $clean_file) . "." . $this->file->guessClientExtension();
     $this->file->move($this->getUploadRootDir() . "tmp/", $clean_file);
     $imagine = new Imagine();
     $size = new Box($width, $height);
     $image = $imagine->open($this->getUploadRootDir() . "tmp/" . $clean_file);
     //original size
     $srcBox = $image->getSize();
     $thumbnail_lg = $image->thumbnail($size, \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND);
     $thumbnail_lg->save($this->getUploadRootDir() . "/" . $clean_file);
     $thumbnail_sm = $image->thumbnail($size, \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND);
     $thumbnail_sm->save($this->getUploadRootDir() . "/thumbnail/" . $clean_file);
     // définit la propriété « path » comme étant le nom de fichier où vous
     // avez stocké le fichier
     $this->path = $clean_file;
     // « nettoie » la propriété « file » comme vous n'en aurez plus besoin
     $this->file = null;
 }
开发者ID:scheffershen,项目名称:a-symfony2-richmedia-cms,代码行数:29,代码来源:Upload.php

示例11: createImages

 public function createImages($aTypeImage, $sImageName)
 {
     foreach ($aTypeImage as $oTypeImage) {
         $oImagine = new Imagine();
         $oImagine->open(self::BUNDLE_IMAGE_DIR . "source/" . $sImageName)->resize(new Box($oTypeImage->getWidth(), $oTypeImage->getHeight()))->save(self::BUNDLE_IMAGE_DIR . $oTypeImage->getDir() . '/' . $sImageName, array('jpeg_quality' => 100));
     }
 }
开发者ID:jbcfrance,项目名称:jlp-immo,代码行数:7,代码来源:ImagesToolsSubscriber.php

示例12: __construct

 public function __construct(GoPro $gopro, GithubDarkroom $githubDarkroom, Imagine $imagine, $watermark)
 {
     $this->gopro = $gopro;
     $this->darkroom = $githubDarkroom;
     $this->imagine = $imagine;
     $this->watermark = $imagine->open($watermark);
 }
开发者ID:nexmo-community,项目名称:javafoto,代码行数:7,代码来源:Developer.php

示例13: resize

 /**
  * @inheritdoc
  */
 public function resize($binaryData, array $settings)
 {
     $imagine = new Imagine();
     $image = $imagine->load($binaryData);
     $image->resize(new Box($settings['width'], $settings['height']));
     return $image->get('png');
 }
开发者ID:xaben,项目名称:XabenMediaBundle,代码行数:10,代码来源:StretchResizer.php

示例14: fix_orientation

function fix_orientation($source, $name)
{
    $imginfo = getimagesize($source);
    $requiredMemory1 = ceil($imginfo[0] * $imginfo[1] * 5.35);
    $requiredMemory2 = ceil($imginfo[0] * $imginfo[1] * ($imginfo['bits'] / 8) * $imginfo['channels'] * 2.5);
    $requiredMemory = (int) max($requiredMemory1, $requiredMemory2);
    $mem_avail = elgg_get_ini_setting_in_bytes('memory_limit');
    $mem_used = memory_get_usage();
    $mem_avail = $mem_avail - $mem_used - 2097152;
    // 2 MB buffer
    if ($requiredMemory > $mem_avail) {
        // we don't have enough memory for any manipulation
        // @TODO - we should only throw an error if the image needs rotating...
        //register_error(elgg_echo('image_orientation:toolarge'));
        return false;
    }
    elgg_load_library('imagine');
    $name = uniqid() . $name;
    $tmp_location = elgg_get_config('dataroot') . 'image_orientation/' . $name;
    //@note - need to copy to a tmp_location as
    // imagine doesn't like images with no file extension
    copy($source, $tmp_location);
    try {
        $imagine = new Imagine();
        $imagine->setMetadataReader(new ExifMetadataReader());
        $autorotate = new Autorotate();
        $autorotate->apply($imagine->open($tmp_location))->save($tmp_location);
        copy($tmp_location, $source);
        unlink($tmp_location);
        return true;
    } catch (Imagine\Exception\Exception $exc) {
        // fail silently, we don't need to rotate it bad enough to kill the script
        return false;
    }
}
开发者ID:n8b,项目名称:VMN,代码行数:35,代码来源:start.php

示例15: getPictureAttributes

 protected function getPictureAttributes($filename, $type)
 {
     $filename = str_replace('!', '.', $filename);
     $filename = str_replace(array('..', '/', '\\'), '', $filename);
     $picture_file_path = APP_ROOT . '/app/cdn/tmp/' . $filename;
     try {
         $imagine = new Imagine();
         $image = $imagine->open($picture_file_path);
         $natural_size = $image->getSize();
         if ($type == 'icon') {
             $scale_ratio = 596 / $natural_size->getWidth();
         } else {
             $scale_ratio = 868 / $natural_size->getWidth();
         }
         $box = new Box($natural_size->getWidth(), $natural_size->getHeight());
         $box = $box->scale($scale_ratio);
         $image->resize($box);
         $image->save($picture_file_path);
     } catch (\Exception $e) {
         @unlink($picture_file_path);
         throw new \Exception($e->getMessage());
     }
     $cdn_url = $this->getContainer()->getParameter('cdn_url');
     $picture_url = $cdn_url . '/tmp/' . $filename;
     return array('natural_size' => $box, 'picture_url' => $picture_url, 'picture_path' => $picture_file_path);
 }
开发者ID:aeshion,项目名称:ZeroPHP,代码行数:26,代码来源:ActionUpload.php


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