本文整理汇总了PHP中Imagine\Gd\Imagine::open方法的典型用法代码示例。如果您正苦于以下问题:PHP Imagine::open方法的具体用法?PHP Imagine::open怎么用?PHP Imagine::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Imagine\Gd\Imagine
的用法示例。
在下文中一共展示了Imagine::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* @param \CActiveRecord $model
* @param string $attribute имя поля, содержащего CUploadedFile. В последствии этому полю будет присвоено имя файла изображения.
* @param \CUploadedFile $image
* @param array $sizes
*
* @throws \CException
*
* @return bool
*/
public function save(\CActiveRecord $model, $attribute = 'image', \CUploadedFile $image, $sizes = [])
{
$folderModel = $this->extractPath($model, $attribute, true);
if (!file_exists($folderModel)) {
mkdir($folderModel);
}
$imageExtension = isset($this->mimeToExtension[$image->getType()]) ? $this->mimeToExtension[$image->getType()] : 'jpg';
$imageId = $this->getRandomHash($model, $attribute);
$imagePathTemp = \Yii::getPathOfAlias('temp') . '/' . $imageId . '.' . $imageExtension;
if ($image->saveAs($imagePathTemp)) {
foreach ($sizes as $sizeName => $size) {
$folderModelAttribute = $this->extractPath($model, $attribute);
if (!file_exists($folderModelAttribute)) {
mkdir($folderModelAttribute);
}
$quality = array_key_exists('quality', $size) ? intval($size['quality']) : self::DEFAULT_QUALITY;
if ($quality <= 0 or $quality > 100) {
$quality = self::DEFAULT_QUALITY;
}
$pathImageSize = $folderModelAttribute . '/' . $imageId . '_' . $sizeName . '.' . $imageExtension;
if (array_key_exists('enabled', $size) and $size['enabled'] == false) {
if (array_key_exists('resave', $size) and $size['resave'] == false) {
rename($imagePathTemp, $pathImageSize);
} else {
$this->processor->open($imagePathTemp)->save($pathImageSize, ['quality' => $quality]);
}
} else {
$this->processor->open($imagePathTemp)->thumbnail(new Box($size['width'], $size['height']), (!isset($size['inset']) or $size['inset']) ? ImageInterface::THUMBNAIL_INSET : ImageInterface::THUMBNAIL_OUTBOUND)->save($pathImageSize, ['quality' => $quality]);
}
}
} else {
throw new \CException('can not save image');
}
return [self::KEY_ID => $imageId, self::KEY_EXT => $imageExtension];
}
示例2: generate
/**
* @test
* @dataProvider photos
* @param $photo
*/
public function generate($photo)
{
$photoThumb = $this->thumbGenerator->generate(new ThumbId(), $photo, new PhotoThumbSize(95, 95), new HttpUrl('http://test'));
$image = $this->imagine->open($photoThumb->photoThumbFile()->filePath());
$this->assertEquals(95, $image->getSize()->getHeight());
$this->assertEquals(95, $image->getSize()->getWidth());
unlink($photoThumb->photoThumbFile()->filePath());
}
示例3: testShouldResize
public function testShouldResize()
{
$size = new Box(100, 10);
$imagine = new Imagine();
$imagine->open('tests/Imagine/Fixtures/large.jpg')->thumbnail($size, ImageInterface::THUMBNAIL_OUTBOUND)->save('tests/Imagine/Fixtures/resized.jpg');
$this->assertTrue(file_exists('tests/Imagine/Fixtures/resized.jpg'));
$this->assertEquals($size, $imagine->open('tests/Imagine/Fixtures/resized.jpg')->getSize());
unlink('tests/Imagine/Fixtures/resized.jpg');
}
示例4: testConvertStringCoordinateToNumber
public function testConvertStringCoordinateToNumber()
{
$imagine = new Imagine();
$flowers = $imagine->open('resources/flowers.jpg');
$archos = $imagine->open('resources/Archos.jpg');
$paste = new Paste($archos, 'center', 'top');
$newImage = $paste->apply($flowers);
$paste = new Paste($archos, 'left', 'bottom');
$newImage = $paste->apply($flowers);
}
示例5: addOverlay
protected function addOverlay($pictureUrl)
{
$imagine = new Imagine();
$picture = $imagine->open($pictureUrl);
$overlay = $imagine->open($this->storagePath . env('FACEBOOK_OVERLAY'));
$x = $picture->getSize()->getWidth() - $overlay->getSize()->getWidth();
$y = $picture->getSize()->getHeight() - $overlay->getSize()->getHeight();
$picture->paste($overlay, new Point($x, $y));
return $picture;
}
示例6: resize
/**
* @param string $origName
* @param string $thumbName
* @param array $origInfo
*/
public function resize($origName, $thumbName, array $origInfo)
{
if ($this->shouldResize($origInfo)) {
$resizeParameters = $this->getResizeParameters($origInfo);
$cropParameters = $this->getCropParameters($resizeParameters);
$resizeSize = $this->factory->getBox($resizeParameters[0], $resizeParameters[1]);
$cropStart = $this->factory->getPoint($cropParameters[0], $cropParameters[1]);
$cropSize = $this->factory->getBox($this->thumbConfig[static::CONFIG_WIDTH], $this->thumbConfig[static::CONFIG_HEIGHT]);
$this->imagine->open($origName)->resize($resizeSize)->crop($cropStart, $cropSize)->save($thumbName);
} else {
copy($origName, $thumbName);
}
}
示例7: transform
/**
* {@inheritDoc}
*/
public function transform($file, array $transformOptions = array(), array $parameters = array())
{
$image = $this->imagine->open($file);
foreach ($transformOptions as $transform => $args) {
if ($transform == 'resize') {
$image->resize(new Box($args[0], $args[1]));
} else {
if ($transform == 'rotate') {
list($angle, $background) = array_pad($transformOptions['rotate'], 2, null);
$image->rotate((int) $angle, $background);
}
}
}
$image->save($file, array('format' => FileUtils::getExtensionFromMime($parameters['mime_type'])));
}
示例8: testResize
public function testResize()
{
$imagine = new Imagine();
$resizer = new Resizer();
$imageDir = __DIR__ . '/../../test-images';
$target = $imageDir . '/resizedimage1.jpg';
$image = $imagine->open($imageDir . '/testimage1.jpg');
$resizer->resize($image, new Box(100, 200), new FocalPoint(0.5, -1), ImageInterface::FILTER_UNDEFINED);
$image->save($target);
$image = $imagine->open($target);
$size = $image->getSize();
$this->assertEquals(100, $size->getWidth());
$this->assertEquals(200, $size->getHeight());
unlink($target);
}
示例9: 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);
}
示例10: 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;
}
}
示例11: __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);
}
示例12: __construct
/**
* @param $image
*/
public function __construct($image)
{
$this->validate($image);
self::$ext = $image->getClientOriginalExtension();
$img = new Img();
$this->image = $img->open($image);
}
示例13: testGetExceptionWithInvalidWatermarkSize
public function testGetExceptionWithInvalidWatermarkSize()
{
$this->setExpectedException('HtImgModule\\Exception\\InvalidArgumentException');
$imagine = new Imagine();
$archos = $imagine->open('resources/Archos.jpg');
$watermark = new Watermark($archos, 'asfd', 'asdf');
}
示例14: 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));
}
示例15: 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;
}