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


PHP Imagine::load方法代码示例

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


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

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

示例2: fire

 public function fire($job, $data)
 {
     $s3 = \Aws::get('s3');
     $response = $s3->getObject(array('Bucket' => $data['bucket'], 'Key' => $data['key']));
     $imagine = new Imagine();
     $image = $imagine->load((string) $response->get('Body'));
     $size = new Box(100, 100);
     $thumb = $image->thumbnail($size);
     $s3->putObject(array('Bucket' => 'testprocqueue', 'Key' => $data['hash'] . '_100x100.' . $data['ext'], 'Body' => $thumb->get($data['ext']), 'ContentType' => $data['mimetype']));
     // Probaby save these to a database here
 }
开发者ID:kakaroto1500,项目名称:Queue-Image-Processing,代码行数:11,代码来源:ImageProcessor.php

示例3: resize

 /**
  * @inheritdoc
  */
 public function resize($binaryData, array $settings)
 {
     if ($settings['width'] === false && $settings['height'] === false) {
         throw new \RuntimeException('Width/Height parameter is missing. Please add at least one parameter.');
     }
     $imagine = new Imagine();
     $image = $imagine->load($binaryData);
     $imageSize = $image->getSize();
     $box = $this->getBox($imageSize, $settings);
     $image->resize($box);
     return $image->get('png');
 }
开发者ID:xaben,项目名称:XabenMediaBundle,代码行数:15,代码来源:InsetResizer.php

示例4: fire

 public function fire($job, $data)
 {
     $s3 = \AWS::createClient('s3');
     try {
         $response = $s3->getObject(array('Bucket' => $data['bucket'], 'Key' => $data['key']));
     } catch (Exception $e) {
         return;
     }
     $imagine = new Imagine();
     $image = $imagine->load((string) $response->get('Body'));
     $size = new Box(100, 100);
     $thumb = $image->thumbnail($size);
     $s3->putObject(array('Bucket' => 'bellated', 'Key' => $data['hash'] . '_100x100.' . $data['ext'], 'Body' => $thumb->get($data['ext']), 'ContentType' => $data['mimetype']));
     // Probaby save these to a database here
 }
开发者ID:ravaboard,项目名称:naujas,代码行数:15,代码来源:ImageProcessor.php

示例5: load

 /**
  * Create a new ImageInterface instance form the given binary string.
  *
  * @param string $string Binary string that holds image information.
  *
  * @return \Webiny\Component\Image\ImageInterface
  */
 public function load($string)
 {
     return new Image($this->instance->load($string));
 }
开发者ID:Webiny,项目名称:Framework,代码行数:11,代码来源:Imagine.php

示例6: imageToBmp

 /**
  * 转换可打印格式
  *
  * @param string $content
  * @return string
  */
 public function imageToBmp($content)
 {
     $imagine = new Imagine();
     $image = $imagine->load($content);
     // 宽 > 384
     if ($image->getSize()->getHeight() > self::CONTENT_MAX_WIDTH) {
         $image->resize($image->getSize()->widen(self::CONTENT_MAX_WIDTH));
     }
     // 转180度
     $image->rotate(180);
     $image->effects()->grayscale();
     /**
      * @var resource $im
      */
     $im = $image->getGdResource();
     // 水平反转
     imageflip($im, IMG_FLIP_HORIZONTAL);
     // 仿生处理
     $converter = new GDIndexedColorConverter();
     $palette = array(array(0, 0, 0), array(255, 255, 255));
     /**
      * @var resource $im
      */
     $im = $converter->convertToIndexedColor($im, $palette, 0.8);
     // 转为单色 bmp
     $dWord = function ($n) {
         return pack("V", $n);
     };
     $word = function ($n) {
         return pack("v", $n);
     };
     $width = imagesx($im);
     $height = imagesy($im);
     $widthPad = str_pad('', (4 - ceil($width / 8) % 4) % 4, "");
     $size = 62 + (ceil($width / 8) + strlen($widthPad)) * $height;
     $header['identifier'] = 'BM';
     $header['file_size'] = $dWord($size);
     $header['reserved'] = $dWord(0);
     $header['bitmap_data'] = $dWord(62);
     $header['header_size'] = $dWord(40);
     $header['width'] = $dWord($width);
     $header['height'] = $dWord($height);
     $header['planes'] = $word(1);
     $header['bits_per_pixel'] = $word(1);
     $header['compression'] = $dWord(0);
     $header['data_size'] = $dWord(0);
     $header['h_resolution'] = $dWord(0);
     $header['v_resolution'] = $dWord(0);
     $header['colors'] = $dWord(0);
     $header['important_colors'] = $dWord(0);
     $header['white'] = chr(255) . chr(255) . chr(255) . chr(0);
     $header['black'] = chr(0) . chr(0) . chr(0) . chr(0);
     $bmp = '';
     foreach ($header as $h) {
         $bmp .= $h;
     }
     $str = '';
     for ($y = $height - 1; $y >= 0; $y--) {
         for ($x = 0; $x < $width; $x++) {
             $rgb = imagecolorat($im, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $gs = $r * 0.299 + $g * 0.587 + $b * 0.114;
             if ($gs > 150) {
                 $color = 0;
             } else {
                 $color = 1;
             }
             $str = $str . $color;
             if ($x == $width - 1) {
                 $str = str_pad($str, 8, "0");
             }
             if (strlen($str) == 8) {
                 $bmp .= chr((int) bindec($str));
                 $str = "";
             }
         }
         $bmp .= $widthPad;
     }
     imagedestroy($im);
     return $bmp;
 }
开发者ID:atans,项目名称:memobird,代码行数:89,代码来源:AbstractPrintContent.php

示例7: loadWithGd

 /**
  * Opens image with Imagine Gd
  *
  * @return AbstractImage
  */
 protected function loadWithGd()
 {
     $imagine = new GdImage();
     return $imagine->load($this->image);
 }
开发者ID:todstoychev,项目名称:icr-bundle,代码行数:10,代码来源:OpenImageHandler.php

示例8: getCroppedImage

 /**
  * @param File $file
  * @param string $urlType
  * @param int $width
  * @param null $height
  * @param null $filename
  * @param null $quality
  *
  * @return File|bool
  */
 protected function getCroppedImage(File $file, $urlType = 'default', $width = 100, $height = null, $filename = null, $quality = null)
 {
     if ($height == null) {
         $height = $width;
     }
     if ($this->repository) {
         if ($file->isImage()) {
             $filename = $this->determineFileName($file, $width, $height, 'c', $filename);
             if ($this->mustBuildImage($file, $filename)) {
                 $binary = $this->getBinary($file);
                 if ($binary) {
                     $imagine = new Imagine();
                     $image = $imagine->load($binary);
                     $size = $image->getSize();
                     $ratioOriginal = $size->getWidth() / $size->getHeight();
                     if ($ratioOriginal > $width / $height) {
                         // create image that has the desired height and an oversize width to crop from
                         $y = $height;
                         $x = $size->getWidth() * ($y / $size->getHeight());
                         $size = new Box($x, $y);
                         $image->resize($size);
                         $start = (int) (($x - $width) / 2);
                         $upperLeft = new Point($start, 0);
                         $image->crop($upperLeft, new Box($width, $height));
                     } else {
                         // create image that has the desired width and an oversize height to crop from
                         $x = $width;
                         $y = $size->getHeight() * ($x / $size->getWidth());
                         $size = new Box($x, $y);
                         $image->resize($size);
                         $start = (int) (($y - $height) / 2);
                         $upperLeft = new Point(0, $start);
                         $image->crop($upperLeft, new Box($width, $height));
                     }
                     $quality = $this->determineQuality($quality);
                     $image->save($this->basePath . '/' . $filename, array('quality' => $quality));
                 } else {
                     return false;
                 }
             }
             $url = $this->baseUrl . '/' . $filename;
             $file->addUrl($urlType, $url);
             return $file;
         }
     }
     return false;
 }
开发者ID:nhagemann,项目名称:anycontent-client-php,代码行数:57,代码来源:ImageVersionCreator.php


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