/**
  * @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');
 }
 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
 }
 /**
  * @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');
 }
Beispiel #4
0
 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
 }
Beispiel #5
0
 /**
  * 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));
 }
 /**
  * 转换可打印格式
  *
  * @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;
 }
 /**
  * Opens image with Imagine Gd
  *
  * @return AbstractImage
  */
 protected function loadWithGd()
 {
     $imagine = new GdImage();
     return $imagine->load($this->image);
 }
 /**
  * @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;
 }