public function testPng() { $file = __DIR__ . '/images/image.png'; $tmpFile = __DIR__ . '/images/tmp.' . static::$library . '.image.png'; $image = Image::create($file, static::$library); $this->assertSame('image/png', $image->getMimeType()); $this->assertSame(512, $image->getWidth()); $this->assertSame(512, $image->getHeight()); //Resize $image->resize(500); $this->assertSame(500, $image->getWidth()); $this->assertSame(500, $image->getHeight()); //Crop $image->crop(400, 300, Image::CROP_ENTROPY); $this->assertSame(400, $image->getWidth()); $this->assertSame(300, $image->getHeight()); $image->crop('50%', '50%'); $this->assertSame(200, $image->getWidth()); $this->assertSame(150, $image->getHeight()); //Save $image->save($tmpFile); $this->assertTrue(is_file($tmpFile)); $image = Image::create($tmpFile, static::$library); $this->assertSame(200, $image->getWidth()); $this->assertSame(150, $image->getHeight()); unlink($tmpFile); }
/** * Get the better quality image found in the icon * * @return Image */ public function getBetterQuality() { $quality = 0; $better = 0; foreach ($this->image as $index => $image) { $q = $image->getImageDepth() + $image->getImageWidth() * $image->getImageHeight(); if ($q > $quality) { $quality = $q; $better = $index; } } $this->image->setIteratorIndex($better); $better = new Image(new ImagickLib($this->image)); $better->format('png'); return $better; }
public function serve() { $imgPath = public_path() . Input::get(Config::get('image::vars.image')); $operations = Input::get(Config::get('image::vars.transform')); $checksum = md5($imgPath . ';' . serialize($operations)); $cacheData = $this->cache->get($checksum); if ($cacheData) { // using cache if (($string = $cacheData['data']) && ($mimetype = $cacheData['mime'])) { header('Content-Type: ' . $mimetype); die($string); } else { throw new \Exception('There was an error with the image cache'); } } else { $image = \Imagecow\Image::create($imgPath, Config::get('image::worker')); if ((int) Config::get('image::compression_quality')) { $image->setCompressionQuality(Config::get('image::compression_quality')); } $image->transform($operations); $cacheData = array('mime' => $image->getMimeType(), 'data' => $image->getString()); $this->cache->put($checksum, $cacheData, $this->cacheLifetime); $image->show(); // if the script didn't die then it will have an error (Imagecow::show() dies when it returns image data) throw new \Exception($image->getError()->getMessage()); } }
/** * Transform the image. * * @param ResponseInterface $response * @param string $transform * * @return ResponseInterface */ private function transform(ResponseInterface $response, $transform) { $image = Image::createFromString((string) $response->getBody()); $image->transform($transform); $body = Middleware::createStream(); $body->write($image->getString()); return $response->withBody($body)->withHeader('Content-Type', $image->getMimeType()); }
public function testResponsiveOperations() { $cookie = '400,300,fast'; $operations = array(array('resize,500,300;max-width=400:resize,400', 'resize,500,300|resize,400'), array('resize,500,300;min-width=400:resize,400', 'resize,500,300|resize,400'), array('resize,500,300;max-width=399:resize,400', 'resize,500,300'), array('resize,500,300;min-width=401:resize,400', 'resize,500,300'), array('resize,500,300;min-width=399,max-width=401:resize,400', 'resize,500,300|resize,400'), array('resize,500,300;min-width=398,max-width=399:resize,400', 'resize,500,300'), array('resize,500,300;min-width=398,max-width=400:resize,400', 'resize,500,300|resize,400')); foreach ($operations as $test) { $this->assertEquals($test[1], Image::getResponsiveOperations($cookie, $test[0])); } }
/** * @param string $file * @param string $public * @return string */ public function pack($file, $public) { if (!($file = $this->check($file))) { return; } $image = Image::fromFile($file); if ($this->settings['quality'] && !strstr($this->settings['transform'], 'quality,')) { $image->quality($this->settings['quality']); } return $image->transform($this->settings['transform'])->getString(); }
public function testIcon() { $file = __DIR__ . '/images/favicon.ico'; $tmpFile = __DIR__ . '/images/tmp.favicon.png'; $icon = new IconExtractor($file); $image = $icon->getBetterQuality(); $this->assertSame(256, $image->getWidth()); $this->assertSame(256, $image->getHeight()); //Save $image->save($tmpFile); $this->assertTrue(is_file($tmpFile)); $image = Image::create($tmpFile); $this->assertSame(256, $image->getWidth()); $this->assertSame(256, $image->getHeight()); }
private function thumb(Request $request, Admin $app) { $query = $request->getQueryParams(); $thumb = $app->getPath($query['thumb']); if (!is_file($thumb)) { return Factory::createResponse(404); } $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $thumb); finfo_close($finfo); if ($mime === 'image/svg+xml') { return Factory::createResponse()->withBody(Factory::createStream(fopen($thumb, 'r')))->withHeader('Content-Type', $mime); } $image = Image::fromFile($thumb); $image->resize(0, 200); echo $image->getString(); return Factory::createResponse()->withHeader('Content-Type', $image->getMimeType()); }
private function endImages(array $data) { if (empty($this->images) || empty($data['id'])) { return null; } clearstatcache(); foreach ($this->images as $name => $size) { if (empty($data[$name])) { continue; } if (!is_file($file = self::getStoragePath($data[$name]))) { continue; } list($width, $height) = explode('x', $size); Image::fromFile($file)->resize($width, $height)->save(); } }
/** * Transform the image. * * @param ServerRequestInterface $request * @param ResponseInterface $response * @param string $transform * * @return ResponseInterface */ private function transform(ServerRequestInterface $request, ResponseInterface $response, $transform) { $image = Image::fromString((string) $response->getBody()); $hints = $this->getClientHints($request); if ($hints) { $image->setClientHints($hints); $response = $response->withHeader('Vary', implode(', ', $hints)); } $image->transform($transform); $body = Middleware::createStream(); $body->write($image->getString()); return $response->withBody($body)->withHeader('Content-Type', $image->getMimeType()); }
/** * Subir multiples imagenes asociadas a un articulo en el mantenimiento de articulos * @return object */ public function api_subir_imagenes_multiple_backend() { $sIdArticulo = Input::get('id_articulo'); $oFile = Input::file('file'); $sNombreImagen = "articulo_" . $sIdArticulo . "_imagen__" . uniqid() . "_" . $oFile->getClientOriginalName(); //echo "<pre>"; //dd($sIdArticulo);die; $Imagen = new Imagen(); $oResultado = $Imagen->Setear_segun_articulo($sNombreImagen, $sIdArticulo); //dd($oResultado[0]->tipo);die; if ($oResultado[0]->tipo != 1) { //cambiar tamaño a imagen $image = Image::createFromFile($oFile); $image->resize(200); //guardar imagen en server $image->save(public_path() . '/imagenes/articulos/' . $sNombreImagen); } return Response::json(array('oResultado' => $oResultado)); }
/** * Register the image worker. * * @return void */ public function registerWorker() { $this->app['image.worker'] = $this->app->share(function ($app) { return Worker::create($app['config']->get('image::worker')); }); }
/** Convert tiff to jpeg * @access public * @param $image */ public function convertTiff() { $tiffDir = IMAGE_PATH . $this->getUserPath() . self::TIFFS; //Determine path to Tiff folder $tiffPath = $tiffDir . $this->getBasename() . self::EXT; //Where we will be saving the file $destination = $this->getUserPath(); //Check if directory exists, if not then make directory if (!is_dir($tiffDir)) { $this->_makeDirectory($tiffDir); } //Create an instance of the image to save $surrogate = Image::create($tiffPath, 'Imagick'); //Set the image to save as jpeg file $surrogate->format('jpg'); //Save to original folder as jpeg $surrogate->save($destination); //return to the resize function $this->resize(); }