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()); }
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"); }
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'); }
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'); }); }
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); }
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'); }