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


PHP Image::canvas方法代码示例

本文整理汇总了PHP中Intervention\Image\Facades\Image::canvas方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::canvas方法的具体用法?PHP Image::canvas怎么用?PHP Image::canvas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Intervention\Image\Facades\Image的用法示例。


在下文中一共展示了Image::canvas方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: pasteFaceOverTemplate

 public function pasteFaceOverTemplate(\Intervention\Image\Image $faceImage, \Kubek\ImageManipulator\Models\TemplateData $templateData)
 {
     // resize the image so it fits into the spot it needs to be pasted in:
     $faceImage = $faceImage->resize($templateData->getCompatibileFaceImageWidth(), $templateData->getCompatibileFaceImageHeight());
     // create an empty image the size of the template
     $fittingFaceImageCanvas = Image::canvas($templateData->getTemplateWidth(), $templateData->getTemplateHeight());
     // paste the fitting face image onto the empty canvas on coords specified in the TemplateData:
     $fittingFaceImageCanvas->insert($faceImage, 'top-left', $templateData->getFaceSpotPlacementX(), $templateData->getFaceSpotPlacementY());
     // paste the template overlay over the canvas with the face image:
     return $fittingFaceImageCanvas->insert($templateData->getTemplateImage());
 }
开发者ID:bancur,项目名称:upfriendly,代码行数:11,代码来源:FaceInserter.php

示例2: testFaceInserterCreatesValidImage

 function testFaceInserterCreatesValidImage()
 {
     $app = $this->createApplication();
     $faceInserter = $app->make("FaceInserter");
     $template = Image::make("./tests/FaceInserterTestData/real_template.png");
     $faceImage = Image::make("./tests/FaceInserterTestData/zuckerberg.jpg");
     $faceImage = $faceImage->resize(317, 282);
     $fittingFaceImage = Image::canvas($template->width(), $template->height());
     $fittingFaceImage->insert($faceImage, 'top-left', 443, 40);
     $resultingImage = $fittingFaceImage->insert($template);
     $resultingImage->save("./tests/FaceInserterTestData/result.png");
 }
开发者ID:bancur,项目名称:upfriendly,代码行数:12,代码来源:FaceInserterTest.php

示例3: getImage

 public function getImage($width_height, $file_name)
 {
     $width_height_arr = explode('x', $width_height);
     $width = $width_height_arr[0];
     $height = $width_height_arr[1];
     $image_path = $this->getOriginDir() . $file_name;
     if (!file_exists($image_path)) {
         $img = Image::canvas($width, $height);
         $img->text('Image not found ;{', 110, 110, function ($font) {
             $font->size(48);
             $font->align('center');
         });
         return $img->response('jpg');
     }
     $img = Image::make($image_path)->fit($width, $height);
     $storage_dir = base_path() . '/public/media/images/' . $width_height;
     $storage_file = $storage_dir . '/' . $file_name;
     if (!file_exists($storage_dir)) {
         mkdir($storage_dir);
     }
     $img->save($storage_file);
     return $img->response('jpg');
 }
开发者ID:serovvitaly,项目名称:new.jp.appros.ru,代码行数:23,代码来源:MediaController.php

示例4: buildAvatar

 protected function buildAvatar()
 {
     $x = $this->width / 2;
     $y = $this->height / 2;
     $this->image = Image::canvas($this->width, $this->height);
     $this->createShape();
     $this->image->text($this->initials, $x, $y, function (AbstractFont $font) {
         $font->file($this->font);
         $font->size($this->fontSize);
         $font->color($this->foreground);
         $font->align('center');
         $font->valign('middle');
     });
 }
开发者ID:vangelis183,项目名称:avatar,代码行数:14,代码来源:Avatar.php

示例5: placeholder

 public function placeholder($text = 'Placeholder', $secondaryText = null)
 {
     $filename = $secondaryText ? $text . '-' . $secondaryText : $text;
     $file = str_slug($filename) . '.jpg';
     $centerText = $secondaryText ?: $text;
     if (!File::exists(public_path('temp/' . $file))) {
         // create Image from file
         $img = Image::canvas(400, 400, '#ccc');
         // Top left
         $img->text($text, 10, 20, function ($font) {
             $font->file(4);
             $font->size(46);
             $font->color('#000000');
         });
         // Top right
         $img->text($text, 390, 20, function ($font) {
             $font->file(4);
             $font->size(46);
             $font->color('#000000');
             $font->align('right');
         });
         // Center
         $img->text($centerText, 200, 200, function ($font) {
             $font->file(4);
             $font->size(46);
             $font->color('#000000');
             $font->align('center');
         });
         // Bottom left
         $img->text($text, 10, 380, function ($font) {
             $font->file(4);
             $font->size(46);
             $font->color('#000000');
             $font->align('left');
         });
         // Bottom right
         $img->text($text, 390, 380, function ($font) {
             $font->file(4);
             $font->size(46);
             $font->color('#000000');
             $font->align('right');
         });
         $img->save(public_path('temp/' . $file));
     }
     return url('temp/' . $file);
 }
开发者ID:tonning,项目名称:media,代码行数:46,代码来源:Media.php

示例6: getImage

 public function getImage($width_height, $file_name)
 {
     $media_id = (int) \Input::get('mid');
     $canvas_color = 'FFFFFF';
     if ($media_id) {
         $media_model = \App\Models\Media::findOrFail($media_id);
         $canvas_color = $media_model->canvas_color;
         if (empty($media_model->file_name) and !empty($media_model->source_url)) {
             $file_extention = 'jpg';
             $file_name = md5(microtime() . rand(0, 1000)) . '.' . $file_extention;
             $source_url = $media_model->source_url;
             if (substr($source_url, 0, 7) != 'http://' and substr($source_url, 0, 8) != 'https://') {
                 $source_url = 'http://' . $source_url;
             }
             \Storage::put('media/images/' . $file_name, file_get_contents($source_url));
             $media_model->file_name = $file_name;
             $media_model->save();
         }
     }
     $width_height_arr = explode('x', $width_height);
     $width = $width_height_arr[0];
     $height = $width_height_arr[1];
     $image_path = $this->getOriginDir() . $file_name;
     if (!file_exists($image_path)) {
         $img = Image::canvas($width, $height);
         $img->text('Image not found ;{', 110, 110, function ($font) {
             $font->size(48);
             $font->align('center');
         });
         return $img->response('jpg');
     }
     $img = Image::make($image_path);
     $source_width = $img->width();
     $source_height = $img->height();
     if ($source_width < $source_height) {
         if ($width = $height or $width > $height) {
             // resize H
             $img->heighten($height);
         }
     } elseif ($source_width > $source_height) {
         if ($width = $height or $width < $height) {
             // resize V
             $img->widen($width);
         }
     } else {
         if ($width > $height) {
             // resize H
             $img->heighten($height);
         }
         if ($width < $height) {
             // resize V
             $img->widen($width);
         }
     }
     $img->resizeCanvas($width, $height, 'center', false, $canvas_color);
     //$img->fit($width, $height);
     $storage_dir = base_path() . '/public/media/images/' . $width_height;
     $storage_file = $storage_dir . '/' . $file_name;
     if (!file_exists($storage_dir)) {
         mkdir($storage_dir);
     }
     $img->save($storage_file);
     return $img->response('jpg');
 }
开发者ID:serovvitaly,项目名称:kotik,代码行数:64,代码来源:MediaController.php


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