當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。