当前位置: 首页>>代码示例>>PHP>>正文


PHP Image\ImageManager类代码示例

本文整理汇总了PHP中Intervention\Image\ImageManager的典型用法代码示例。如果您正苦于以下问题:PHP ImageManager类的具体用法?PHP ImageManager怎么用?PHP ImageManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ImageManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: processAvatar

 public function processAvatar($path)
 {
     $manager = $this->imgManager->make($path);
     $manager->orientate();
     $manager->fit($this->width);
     $name = $this->getFileName();
     $manager->save($this->getUploadPath($name));
     return $name;
 }
开发者ID:quentin-sommer,项目名称:WebTv,代码行数:9,代码来源:AvatarManager.php

示例14: run

 /**
  * Perform image manipulations.
  * @param  string $source Source image binary data.
  * @param  array  $params The manipulation params.
  * @return string Manipulated image binary data.
  */
 public function run($source, array $params)
 {
     $image = $this->imageManager->make($source);
     foreach ($this->manipulators as $manipulator) {
         $manipulator->setParams($params);
         $image = $manipulator->run($image);
     }
     return $image->getEncoded();
 }
开发者ID:whismat,项目名称:glide,代码行数:15,代码来源:Api.php

示例15: resize

 public function resize($image)
 {
     $width = config('medias.max_size.width');
     $height = config('medias.max_size.height');
     // this orientate method needs to be called because sometimes
     // images uploaded came rotated, but need to be ajusted
     $img = $this->image->make(Storage::disk(config('medias.disk'))->get($image))->orientate();
     if ($img->width() <= $width && $img->height() <= $height) {
         return;
     }
     if ($img->width() > $width && $img->height() > $height) {
         $img->resize($width, $height, function ($constraint) {
             $constraint->aspectRatio();
         });
         Storage::disk(config('medias.disk'))->put($image, $img->stream());
         return;
     }
     if ($img->width() > $width) {
         $height = null;
     } elseif ($img->height() > $height) {
         $width = null;
     }
     $img->resize($width, $height, function ($constraint) {
         $constraint->aspectRatio();
     });
     Storage::disk(config('medias.disk'))->put($image, $img->stream());
 }
开发者ID:escapework,项目名称:laramedias,代码行数:27,代码来源:MediasResizeService.php


注:本文中的Intervention\Image\ImageManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。