本文整理汇总了PHP中Intervention\Image\ImageManager类的典型用法代码示例。如果您正苦于以下问题:PHP ImageManager类的具体用法?PHP ImageManager怎么用?PHP ImageManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: thumbAction
public function thumbAction(Request $request, Application $app)
{
$source = $request->get('src', false);
$width = $request->get('width', 250);
// Do requested thumbnail in correct format already exists ?
if ($app['flysystems']['thumbs']->has($width . "/" . $source)) {
return $app->redirect($request->getBasePath() . '/thumbs/' . $width . '/' . $source, 301);
}
// Do requested file exists ?
if (!$source || !$app['flysystems']['local']->has($source)) {
return new Response("Source file not found.", 404);
}
try {
$contents = $app['flysystems']['local']->read($source);
$imageManager = new ImageManager();
$image = $imageManager->make($contents);
$image->resize($width, null, function ($constraint) {
$constraint->aspectRatio();
});
$info = $app['flysystems']['local']->getWithMetadata($source, ['mimetype']);
$image->encode($info['mimetype']);
$app['flysystems']['thumbs']->put($width . "/" . $source, $image);
return $app->redirect($request->getBasePath() . '/thumbs/' . $width . '/' . $source, 301);
} catch (\Exception $e) {
return new Response("Erreur !", 500);
}
// Should not happen, everything failed. Display not found image :(
return $app->redirect($request->getBasePath() . '/assets/img/' . $width . '_not-found.png', 302);
}
开发者ID:pygillier,项目名称:piTitle,代码行数:29,代码来源:AppController.php
示例2: postCrop
public function postCrop()
{
$form_data = Input::all();
$image_url = $form_data['imgUrl'];
// resized sizes
$imgW = $form_data['imgW'];
$imgH = $form_data['imgH'];
// offsets
$imgY1 = $form_data['imgY1'];
$imgX1 = $form_data['imgX1'];
// crop box
$cropW = $form_data['width'];
$cropH = $form_data['height'];
// rotation angle
$angle = $form_data['rotation'];
$filename_array = explode('/', $image_url);
$filename = $filename_array[sizeof($filename_array) - 1];
$manager = new ImageManager();
$image = $manager->make($image_url);
$image->resize($imgW, $imgH)->rotate(-$angle)->crop($cropW, $cropH, $imgX1, $imgY1)->save(env('UPLOAD_PATH') . 'cropped-' . $filename);
if (!$image) {
return Response::json(['status' => 'error', 'message' => 'Server error while uploading'], 200);
}
return Response::json(['status' => 'success', 'url' => env('URL') . 'uploads/cropped-' . $filename], 200);
}
开发者ID:codingo-me,项目名称:laravel-croppic,代码行数:25,代码来源:CropController.php
示例3: handle
/**
* @param MediaRepositoryInterface $media
* @param ImageManager $images
* @param Filesystem $files
* @return bool
* @throws Exception
*/
public function handle(MediaRepositoryInterface $media, ImageManager $images, Filesystem $files)
{
list($width, $height) = $this->dimensions($this->size);
$path = $this->getPath($files);
$constraint = $this->constraint($width, $height);
$image = $images->cache(function ($image) use($width, $height, $constraint) {
if ($this->cachedPath) {
$image = $image->make($this->cachedPath);
} else {
$image = $image->make(public_path($this->image->path));
}
$image->resize($width, $height, $constraint);
}, 60, true)->save($path);
if ($image) {
//always fetch the actual width and height from the image,
//one of them could have been null to auto scale the image.
$width = $image->getWidth();
$height = $image->getHeight();
//use html public path to store in database
$path = $this->getPath($files, true);
try {
$media->createThumbnailImage($this->getPayload($width, $height, $path), $this->image);
} catch (Exception $e) {
$files->delete(public_path($path));
unset($image);
return false;
}
unset($image);
}
}
开发者ID:jaffle-be,项目名称:framework,代码行数:37,代码来源:ResizeImage.php
示例4: handle
/**
* @param UploadAvatar $command
* @return \Flarum\Core\Users\User
* @throws \Flarum\Core\Exceptions\PermissionDeniedException
*/
public function handle(UploadAvatar $command)
{
$actor = $command->actor;
$user = $this->users->findOrFail($command->userId);
// Make sure the current user is allowed to edit the user profile.
// This will let admins and the user themselves pass through, and
// throw an exception otherwise.
if ($actor->id !== $user->id) {
$user->assertCan($actor, 'edit');
}
$tmpFile = tempnam(sys_get_temp_dir(), 'avatar');
$command->file->moveTo($tmpFile);
$manager = new ImageManager();
$manager->make($tmpFile)->fit(100, 100)->save();
event(new AvatarWillBeSaved($user, $actor, $tmpFile));
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
$mount->delete($file);
}
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
$user->changeAvatarPath($uploadName);
$mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$user->save();
$this->dispatchEventsFor($user);
return $user;
}
开发者ID:redstarxz,项目名称:flarumone,代码行数:31,代码来源:UploadAvatarHandler.php
示例5: saveImageLocally
/**
* @param \Onyx\Destiny\Objects\Hash $hash
* @param string $index
* @return bool
*/
public static function saveImageLocally($hash, $index = 'extra')
{
// BUG: Can't use variable object indexes implicitly
// $hash->{$index} should work but doesn't
// map the index explicitly with the attributes dumped into $bug
$bug = $hash->getAttributes();
$url = "https://bungie.net" . $bug[$index];
$name = $index != 'extra' ? '_bg' : null;
$name = $hash->hash . $name;
// Make sure we aren't trying to save something that isn't an image
// We only need this check because we cheat and store all hash related objects
// in one table. This means we have crazy cheats to get things done.
if (strlen($bug[$index]) < 5) {
return false;
}
$location = public_path('uploads/thumbs/');
$filename = $name . "." . pathinfo($bug[$index], PATHINFO_EXTENSION);
if (File::isFile($location . $filename)) {
return true;
}
if ($hash instanceof Hash) {
$manager = new ImageManager();
try {
$img = $manager->make($url);
$img->save($location . $filename);
} catch (NotReadableException $e) {
Log::error('Could not download: ' . $url);
}
return true;
}
}
开发者ID:GMSteuart,项目名称:PandaLove,代码行数:36,代码来源:Images.php
示例6: data
/**
* {@inheritdoc}
*/
public function data(ServerRequestInterface $request, Document $document)
{
$this->assertAdmin($request->getAttribute('actor'));
$file = array_get($request->getUploadedFiles(), 'favicon');
$tmpFile = tempnam($this->app->storagePath() . '/tmp', 'favicon');
$file->moveTo($tmpFile);
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
if ($extension !== 'ico') {
$manager = new ImageManager();
$encodedImage = $manager->make($tmpFile)->resize(64, 64, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('png');
file_put_contents($tmpFile, $encodedImage);
$extension = 'png';
}
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($this->app->publicPath() . '/assets'))]);
if (($path = $this->settings->get('favicon_path')) && $mount->has($file = "target://{$path}")) {
$mount->delete($file);
}
$uploadName = 'favicon-' . Str::lower(Str::quickRandom(8)) . '.' . $extension;
$mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$this->settings->set('favicon_path', $uploadName);
return parent::data($request, $document);
}
开发者ID:flarum,项目名称:core,代码行数:28,代码来源:UploadFaviconController.php
示例7: handle
/**
* @param UploadAvatar $command
* @return \Flarum\Core\User
* @throws \Flarum\Core\Exception\PermissionDeniedException
*/
public function handle(UploadAvatar $command)
{
$actor = $command->actor;
$user = $this->users->findOrFail($command->userId);
if ($actor->id !== $user->id) {
$this->assertCan($actor, 'edit', $user);
}
$tmpFile = tempnam($this->app->storagePath() . '/tmp', 'avatar');
$command->file->moveTo($tmpFile);
$file = new UploadedFile($tmpFile, $command->file->getClientFilename(), $command->file->getClientMediaType(), $command->file->getSize(), $command->file->getError(), true);
$this->validator->assertValid(['avatar' => $file]);
$manager = new ImageManager();
$manager->make($tmpFile)->fit(100, 100)->save();
$this->events->fire(new AvatarWillBeSaved($user, $actor, $tmpFile));
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
$mount->delete($file);
}
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
$user->changeAvatarPath($uploadName);
$mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$user->save();
$this->dispatchEventsFor($user, $actor);
return $user;
}
开发者ID:asifalimd,项目名称:core,代码行数:30,代码来源:UploadAvatarHandler.php
示例8: image
public function image($filename)
{
$mediaArchivePath = str_replace('\\', '\\\\', storage_path('app/media-archive/' . Auth::user()->id . '/'));
// return Storage::disk('local')->get('media-archive/'. Auth::user()->id . '/' . $filename );
$manager = new ImageManager();
return $manager->make($mediaArchivePath . $filename)->response();
}
开发者ID:sohel364,项目名称:inzaana_core,代码行数:7,代码来源:MediaController.php
示例9: createImageSet
/**
* Create an array of resized images
*
* @param string $image
* @param int $id
*/
protected function createImageSet($path, $file)
{
$manager = new ImageManager(['driver' => 'imagick']);
$image = $manager->make($path . $file);
$image->resize(768, null, function ($constraint) {
$constraint->aspectRatio();
})->sharpen(6)->save($path . '768_' . $file);
$image->resize(600, null, function ($constraint) {
$constraint->aspectRatio();
})->sharpen(6)->save($path . '600_' . $file);
$image->resize(523, null, function ($constraint) {
$constraint->aspectRatio();
})->sharpen(6)->save($path . '523_' . $file);
$image->resize(480, null, function ($constraint) {
$constraint->aspectRatio();
})->sharpen(6)->save($path . '480_' . $file);
$image->resize(423, null, function ($constraint) {
$constraint->aspectRatio();
})->sharpen(6)->save($path . '423_' . $file);
$image->resize(313, null, function ($constraint) {
$constraint->aspectRatio();
})->sharpen(6)->save($path . '313_' . $file);
$image->destroy();
unlink($path . $file);
}
开发者ID:edrobotij,项目名称:portfolio,代码行数:31,代码来源:PortfolioController.php
示例10: handle
/**
* @param UploadAvatar $command
* @return \Flarum\Core\User
* @throws \Flarum\Core\Exception\PermissionDeniedException
*/
public function handle(UploadAvatar $command)
{
$actor = $command->actor;
$user = $this->users->findOrFail($command->userId);
if ($actor->id !== $user->id) {
$this->assertCan($actor, 'edit', $user);
}
$tmpFile = tempnam($this->app->storagePath() . '/tmp', 'avatar');
$command->file->moveTo($tmpFile);
try {
$file = new UploadedFile($tmpFile, $command->file->getClientFilename(), $command->file->getClientMediaType(), $command->file->getSize(), $command->file->getError(), true);
$this->validator->assertValid(['avatar' => $file]);
$manager = new ImageManager();
// Explicitly tell Intervention to encode the image as JSON (instead of having to guess from the extension)
$encodedImage = $manager->make($tmpFile)->fit(100, 100)->encode('jpg', 100);
file_put_contents($tmpFile, $encodedImage);
$this->events->fire(new AvatarWillBeSaved($user, $actor, $tmpFile));
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => $this->uploadDir]);
if ($user->avatar_path && $mount->has($file = "target://{$user->avatar_path}")) {
$mount->delete($file);
}
$uploadName = Str::lower(Str::quickRandom()) . '.jpg';
$user->changeAvatarPath($uploadName);
$mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$user->save();
$this->dispatchEventsFor($user, $actor);
return $user;
} catch (Exception $e) {
@unlink($tmpFile);
throw $e;
}
}
开发者ID:Luceos,项目名称:core,代码行数:37,代码来源:UploadAvatarHandler.php
示例11: generate
public function generate()
{
$image_manager = new ImageManager();
$this->image = $image_manager->make($this->source_path);
if ($this->width() && $this->height()) {
$this->image->fit($this->width(), $this->height(), function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
} else {
if ($this->width() || $this->height()) {
$this->image->resize($this->width(), $this->height(), function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}
}
if ($this->cropWidth() || $this->cropHeight()) {
$cw = $this->cropWidth() ?: $this->width() ?: $this->image->width();
$ch = $this->cropHeight() ?: $this->height() ?: $this->image->height();
if (!is_null($this->cropX()) || !is_null($this->cropY())) {
$cx = is_null($this->cropX()) ? $cw / 2 - $this->image->width() / 2 : $this->cropX();
$cy = is_null($this->cropY()) ? $ch / 2 - $this->image->height() / 2 : $this->cropY();
$this->image->crop($cw, $ch, round($cx), round($cy));
} else {
$this->image->resizeCanvas($cw, $ch, 'center', false, 'ffffff');
}
}
if ($this->rotation) {
$this->image->rotate($this->rotation);
}
$this->image->save($this->dest_path);
return $this;
}
开发者ID:crobays,项目名称:asset,代码行数:34,代码来源:ImageGenerator.php
示例12: setUp
public function setUp()
{
$manager = new ImageManager();
$this->jpg = $manager->canvas(100, 100)->encode('jpg');
$this->png = $manager->canvas(100, 100)->encode('png');
$this->gif = $manager->canvas(100, 100)->encode('gif');
$this->manipulator = new Encode();
}
开发者ID:whismat,项目名称:glide,代码行数:8,代码来源:EncodeTest.php
示例13: icon
/**
* Create Icon From Original
*/
public function icon($photo, $filename)
{
$manager = new ImageManager();
$image = $manager->make($photo)->encode('jpg')->resize(93, null, function ($constraint) {
$constraint->aspectRatio();
})->save(Config::get('images.icon_size') . $filename);
return $image;
}
开发者ID:wilderguzman,项目名称:lugrawibe,代码行数:11,代码来源:ImageRepository.php
示例14: icon
/**
* Create Icon From Original
*/
public function icon($photo, $filename)
{
$manager = new ImageManager();
$image = $manager->make($photo)->encode('jpg')->resize(700, null, function ($constraint) {
$constraint->aspectRatio();
})->save('images/icon/' . $filename);
return $image;
}
开发者ID:adrianicn,项目名称:IguanaTrip,代码行数:11,代码来源:ImageRepository.php
示例15: icon
/**
* Create Icon From Original
*/
public function icon($photo, $filename)
{
$manager = new ImageManager();
$image = $manager->make($photo)->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
})->save(public_path('images/icon_size/' . $filename));
return $image;
}
开发者ID:jeremykenedy,项目名称:dropzone-laravel-image-upload,代码行数:11,代码来源:ImageRepository.php
示例16: test_upload_object
public function test_upload_object()
{
$this->assertInstanceOf('\\Dugun\\UploadBundle\\Service\\DugunUploadService', $this->service);
$interventionImageManager = new ImageManager();
$image = $interventionImageManager->make(__DIR__ . '/../Resources/assets/test/file1.jpg');
$this->service->upload($image, 'test.jpg', $delete = false, $overwrite = true);
$image = new UploadedFile(__DIR__ . '/../Resources/assets/test/file1.jpg', 'file1.jpg', 'image/jpeg');
$result = $this->service->upload($image, 'test.jpg', $delete = false, $overwrite = true);
}
开发者ID:duguncom,项目名称:DugunUploadBundle,代码行数:9,代码来源:UploadTest.php
示例17: createThumbnail
/**
* creates a thumbnail
*
* @param $imagePath
* @param null $width
* @param null $height
* @param $target
* @return bool
*/
public static function createThumbnail($imagePath, $width = null, $height = null, $target)
{
$manager = new ImageManager();
$manager->make($imagePath)->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save($target);
return true;
}
开发者ID:darryldecode,项目名称:laravelbackend,代码行数:18,代码来源:Image.php
示例18: testConfigure
public function testConfigure()
{
$overwrite = array('driver' => 'none', 'bar' => 'none');
$config = array('driver' => 'foo', 'bar' => 'baz');
$manager = new ImageManager($overwrite);
$manager->configure($config);
$this->assertEquals('foo', $manager->config['driver']);
$this->assertEquals('baz', $manager->config['bar']);
}
开发者ID:hilmysyarif,项目名称:sic,代码行数:9,代码来源:ImageManagerTest.php
示例19: load
public function load($location)
{
try {
$imageManager = new ImageManager();
$image_data = $imageManager->make($location);
return new Image(["mime" => $image_data->mime(), "data" => $image_data->encode()]);
} catch (\Intervention\Image\Exception\NotReadableException $e) {
throw new ImageNotFoundException();
}
}
开发者ID:apsdsm,项目名称:spectre,代码行数:10,代码来源:InterventionImageLoader.php
示例20: setAvatar
public function setAvatar($user_id, $avatar)
{
$source = $avatar['tmp_name'];
$filename = $avatar['name'];
$manager = new ImageManager();
$upload_dir = BASEPATH . '../assets/upload/avatar/';
$image = $manager->make($source);
$image->save($upload_dir . $filename, 90);
$data['avatar'] = $filename;
$this->db->where('user_id', $user_id);
$this->db->update('profile', $data);
}
开发者ID:singgihsap,项目名称:elearning,代码行数:12,代码来源:Mod_user.php
注:本文中的Intervention\Image\ImageManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论