本文整理汇总了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));
}
示例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);
}
示例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()));
}
示例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;
}
示例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();
}
}
示例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');
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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));
}
}
示例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);
}
示例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');
}
示例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;
}
}
示例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);
}