public function setFile($file) { $this->file = $file; $this->image = Image::make($this->file); $this->iptc = $this->image->iptc(); $this->exif = $this->image->exif(); return $this; }
public function run(File $file) { $image = $this->intervention->make($file->getRealPath()); $image->orientate(); $image->save(null, 100); $image->destroy(); }
public function run(File $file) { $image = $this->intervention->make($file->getRealPath()); $preserveRatio = $this->preserveRatio; $image->resize($this->width, $this->height, function ($constraint) use($preserveRatio) { if ($preserveRatio) { $constraint->aspectRatio(); } }); $image->save(null, 100); $image->destroy(); }
public function savePoster($filename) { $finfo = new finfo(FILEINFO_MIME_TYPE); $mime = $finfo->file($filename); $extensions = ['image/jpg' => '.jpg', 'image/jpeg' => '.jpg', 'image/png' => '.png', 'image/gif' => '.gif']; $extension = '.jpg'; if (!isset($extensions[$mime])) { $extension = $extensions[$mime]; } $newFilename = uniqid() . $extension; $folder = "./images/posters/originals"; // no trailing slash if (!is_dir($folder)) { mkdir($folder, 0777, true); } $destination = $folder . "/" . $newFilename; move_uploaded_file($filename, $destination); $this->poster = $newFilename; //240x300 80x100 if (!is_dir("./images/posters/300h")) { mkdir("./images/posters/300h", 0777, true); } $img = Image::make($destination); $img->fit(240, 300); $img->save("./images/posters/300h/" . $newFilename); if (!is_dir("./images/posters/100h")) { mkdir("./images/posters/100h", 0777, true); } $img = Image::make($destination); $img->fit(80, 100); $img->save("./images/posters/100h/" . $newFilename); }
/** * Upload File with Request * * @param User $user * @param \Illuminate\Http\Request::file() $file */ private function uploadFile($user, $file, $type) { $client_original_name = $file->getClientOriginalName(); $fileName = time() . '_' . $client_original_name; //? $destinationPath = 'uploads/profile'; $path = $destinationPath . '/' . $fileName; $image = Image::make($file->getRealPath()); switch ($type) { case 'profile_photo': $image->fit(128, 128, function ($constraint) { $constraint->upsize(); })->save($path); break; case 'profile_cover': $image->resize(1440, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save($path); break; } $original_name = pathinfo($client_original_name, PATHINFO_FILENAME); $file = File::create(['url' => $path, 'original_name' => $original_name, 'type' => $type]); return $file->id; }
public function setAvatarAttribute($avatar) { if (is_object($avatar) && $avatar->isValid()) { ImageManagerStatic::make($avatar)->fit(150, 150)->save(public_path() . "/img/avatars/{$this->id}.jpg"); $this->attributes['avatar'] = true; } }
public function image($display_size, $image_size, $image_path) { $max_age_days = 30; $pixel_density = 2; $display_sizes = ['sm' => 320, 'md' => 480, 'lg' => 600, 'xl' => 960]; $image_sizes = ['full' => 1, 'half' => 0.5, 'third' => 0.34, 'quarter' => 0.25]; $compressions = ['sm' => 80, 'md' => 80, 'lg' => 80, 'xl' => 80]; $src_path = config('site.assets_path') . '/' . $image_path; $new_width = (int) ($display_sizes[$display_size] * $pixel_density * $image_sizes[$image_size]); $compression = $compressions[$display_size]; $colors = (int) Input::get('colors'); // Throw 404 if image does not exist if (!file_exists($src_path)) { return response('image not found', 404); } $img = Image::make($src_path); $img->resize($new_width, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); if ($colors > 0) { $img->limitColors($colors, '#ffffff'); } $response = Response::make($img->encode(null, $compression), 200); $response->header('Content-Type', $img->mime()); $response->header('Cache-Control', 'max-age=' . $max_age_days * 24 * 60 * 60 . ', public'); return $response; }
public function image($image, $x, $y, $width) { if ($width) { $image = Image::make($image)->widen($width); } $this->baseimg->insert($image, "bottom-right", $x, $y); }
/** * Description * @param object $request * @param string $destino * @return array */ public function cropImage($request, $destino) { $data = $request->all(); if ($request->hasFile('avatar')) { $novoNome = date('d-m-Y-h-i-s') . '-' . $request->file('avatar')->getClientOriginalName(); if ($data['x1'] !== '' && $data['x2'] !== '' && $data['y1'] !== '' && $data['y2'] !== '') { $w = $data['x2'] - $data['x1']; $h = $data['y2'] - $data['y1']; $x = $data['x1']; $y = $data['y1']; Image::configure(array('driver' => 'gd')); $image = Image::make($request->file('avatar')); // width, height, $x, $y $image->crop($w, $h, $x, $y); $image->save($destino . $novoNome); } else { $image = Image::make($request->file('avatar')); $image->save($destino . $novoNome); } $data["avatar"] = $novoNome; } unset($data['_token']); unset($data['x1']); unset($data['y1']); unset($data['x2']); unset($data['y2']); return $data; }
public function upload() { $file = Input::file('file'); $input = array('image' => $file); $rules = array('image' => 'image'); $validator = Validator::make($input, $rules); $imagePath = 'public/uploads/'; $thumbPath = 'public/uploads/thumbs/'; $origFilename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $mimetype = $file->getMimeType(); if (!in_array($extension, $this->whitelist)) { return Response::json('Supported extensions: jpg, jpeg, gif, png', 400); } if (!in_array($mimetype, $this->mimeWhitelist) || $validator->fails()) { return Response::json('Error: this is not an image', 400); } $filename = str_random(12) . '.' . $extension; $image = ImageKit::make($file); //save the original sized image for displaying when clicked on $image->save($imagePath . $filename); // make the thumbnail for displaying on the page $image->fit(640, 480)->save($thumbPath . 'thumb-' . $filename); if ($image) { $dbimage = new Image(); $dbimage->thumbnail = 'uploads/thumbs/thumb-' . $filename; $dbimage->image = 'uploads/' . $filename; $dbimage->original_filename = $origFilename; $dbimage->save(); return $dbimage; } else { return Response::json('error', 400); } }
public function testMake() { $manager = Mockery::mock('Intervention\\Image\\ImageManager'); $managerStatic = new ImageManagerStatic($manager); $img = $managerStatic->make('tests/images/tile.png'); $this->assertInstanceOf('Intervention\\Image\\Image', $img); }
public function updateProfile(Request $request) { $input = Input::except('_token', 'image', 'x', 'y', 'w', 'h', 'old_image'); foreach ($input as $key => $value) { $update = User::find(Auth::user()->id); $update->{$key} = $value; $update->save(); } $image = Input::file('image'); if (!empty($image)) { $filename = time() . '.' . $image->getClientOriginalExtension(); $path = public_path('profiles/' . $filename); $image_x = $request->x; $image_y = $request->y; $image_width = $request->w; $image_height = $request->h; $old_image = $request->old_image; Image::make($image->getRealPath())->crop($image_width, $image_height, $image_x, $image_y)->resize(250, 250)->save($path); File::delete($old_image); $update = User::find(Auth::user()->id); $update->image = $filename; $update->save(); } return Redirect::back(); }
public static function uploadBeerImg_callback($request, $fileimage) { $image_unique_id = date('Ymdhis') . rand(0, 9999); $beer_meta = new BeerImg(); $beer_meta->beer_id = $request['beer_id']; $beer_meta->description = !empty($request['img_description']) ? $request['img_description'] : null; $beer_name = !empty($request['img_description']) ? $request['img_description'] : null; $imageName = "beerhit.com_" . strtolower($beer_name) . $request['beer_id'] . $image_unique_id . '.' . $fileimage->getClientOriginalExtension(); $path = public_path('/images/catalog/' . $imageName); $img = ImageManagerStatic::make($fileimage); // resize the image to a width of 960 // and constrain aspect ratio (auto width) $img->resize(960, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $img->save($path); //Save image information to database $beer_meta->img_id = $image_unique_id; $beer_meta->filename = $imageName; $beer_meta->path = '/images/catalog/' . $imageName; $beer_meta->user_id = \Auth::user()->id; $beer_meta->place_id = $request['fb_place_id']; $beer_meta->save(); \UserBeerHelper::userLog(\Auth::user()->id, $request['beer_id'], 200, $request['fb_place_id'], $image_unique_id); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $images = $request->input('images'); $gallery_name = 'gallery_' . time(); $directory = 'uploads/' . $gallery_name . '/'; mkdir($directory, 0755); $gallery = Gallery::create(['name' => $gallery_name, 'directory' => $directory]); foreach ($images as $image) { $url = $image['url']; $img = Image::make($url); $img->resize(800, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); preg_match('/\\.[^\\.]+$/i', $url, $ext); $filename = $directory . time() . $ext[0]; $stream = $img->stream(); $s3 = Storage::disk('s3'); $s3->put($filename, $stream->__toString(), 'public'); $client = $s3->getDriver()->getAdapter()->getClient(); $public_url = $client->getObjectUrl(env('S3_BUCKET'), $filename); $gallery->images()->create(['url' => $public_url]); } $response = ['message' => 'Images successfully uploaded', 'redirect' => url('gallery', $gallery_name)]; return response()->json($response); }
function f_img_resize($path, $w, $h, $watermark = null) { if (!$path) { return; } //Image::configure(array('driver' => 'gd')); $path_0 = $path; if (!file_exists(WEB . $path_0)) { return; } $path = str_replace('/upload/', '/upload/thum/', $path); $new = file_dir($path); $ext = file_ext($path); $new = $new . '/' . file_name($path) . "_{$w_}{$h}" . '.' . $ext; if (file_exists(WEB . $new)) { return $new; } echo WEB . $path_0; $img = Image::make(WEB . $path_0); $img->resize($w, $h); if (!is_dir(WEB . file_dir($new))) { mkdir(WEB . $new, 0777, true); } if ($watermark) { $img->insert(WEB . $watermark); } $img->save(WEB . $new); return $new; }
public function testMake() { $manager = Mockery::mock('Intervention\\Image\\ImageManager'); $manager->shouldReceive('make')->with('foo')->once(); $managerStatic = new ImageManagerStatic($manager); $managerStatic->make('foo'); }
public function avatarupdate(AvatarRequest $request) { Image::make($request->file('avatar'))->resize(100, 100)->encode('jpg')->save(base_path() . '/public/images/avatar/avatar' . Auth::id() . '.jpg'); $user = Auth::user(); $user->avatar = '/images/avatar/avatar' . Auth::id() . '.jpg'; $user->save(); return redirect('settings'); }
private function resize($in, $w, $h, $out) { $img = Image::make($in)->resize($w, $h, function ($constraint) { $constraint->aspectRatio(); }); $img->save($out, 100); return $img; }
public function cropImage($request) { $x = (int) $request->input('x'); $y = (int) $request->input('y'); $width = (int) $request->input('w'); $height = (int) $request->input('h'); Image::make(Input::file('img_pre'))->crop($width, $height, $x, $y)->save('client/img/slides_bg/cropped-' . Input::file('img_pre')->getClientOriginalName()); }
/** * Create an image and get informations about it * * @param string $source * * @throws \Exception if cannot find or load the file */ public function __construct($source) { $this->source = $source; if (!is_file($this->source) && !is_uploaded_file($this->source)) { throw new Exceptions\NotFoundException('file not found'); } $this->image = InterventionImage::make($source); }
public function actions() { return ['picture-upload' => ['class' => UploadAction::className(), 'deleteRoute' => 'picture-delete', 'on afterSave' => function ($event) { /* @var $file \League\Flysystem\File */ $file = $event->file; $img = ImageManagerStatic::make($file->read())->fit(self::IMAGE_MAX_WIDTH, self::IMAGE_MAX_HEIGHT); $file->put($img->encode()); }], 'picture-delete' => ['class' => DeleteAction::className()]]; }
/** * @return array */ public function actions() { return ['avatar-upload' => ['class' => UploadAction::className(), 'deleteRoute' => 'avatar-delete', 'on afterSave' => function ($event) { /* @var $file \League\Flysystem\File */ $file = $event->file; $img = ImageManagerStatic::make($file->read())->fit(215, 215); $file->put($img->encode()); }], 'avatar-delete' => ['class' => DeleteAction::className()]]; }
public function convertBase64ToTmpFile($rawBase64) { $name = time() . '_' . mt_rand(0, 999999999) . '.png'; $photo = ImageManagerStatic::make($rawBase64); $photo->widen($photo->width() / 1.5); $photo->encode('png'); $photo->save('share/' . $name); return $name; }
public function store(array $inputs) { $photoSerie_id = $inputs['serie_id']; $photoSerie = GallerySerie::where('id', '=', $photoSerie_id)->firstOrFail(); $photoCategory = GalleryCategory::where('id', '=', $photoSerie['category_id'])->firstOrFail(); $path = config('gallery.path') . $photoCategory['slug'] . '/' . $photoSerie['slug']; $first = GalleryImage::where('serie_id', '=', $photoSerie_id)->count(); $first > 0 ? $first = 0 : ($first = 1); $valid = true; $files_count = 0; $uploads_count = 0; $files = Input::file('images'); foreach ($files as $file) { // Validate each file $rules = array('file' => 'image'); $validator = Validator::make(array('file' => $file), $rules); if ($validator->fails()) { $valid = false; } $files_count++; } if ($valid == true) { foreach ($files as $file) { $extension = $file->getClientOriginalExtension(); $image = new GalleryImage(array('extension' => $extension, 'path' => $path, 'serie_id' => $photoSerie_id, 'first' => $first)); $image->save(); $id = GalleryImage::max('id'); //On sauve le fichier $destinationPath = public_path() . $path; if (!is_dir($destinationPath)) { mkdir($destinationPath, 0777, true); } $filename = $id . '.' . $extension; $file->move($destinationPath, $filename); $img = IntImage::make($destinationPath . '/' . $filename)->orientate(); $img->save($destinationPath . '/' . $id . '.' . $extension); $img->resize(null, 125, function ($constraint) { $constraint->aspectRatio(); }); $img->save($destinationPath . '/' . $id . '_thumb.' . $extension); $uploads_count++; } } if ($uploads_count == $files_count) { $result = 'ok'; } elseif ($files_count == 0) { $result = 'nf'; //no files selected } elseif ($valid == false) { $result = 'valid_fails'; //some files are not images } else { $result = 'pb'; // a problem occurred } return $result; }
public function getTest3() { $this->layout = null; $img = Image::make('5721fc06d139a.jpg'); // $img = Image::make('5721fc06d139a.jpg')->resize(300, 300)->greyscale(); // $img = Image::make('5721fc06d139a.jpg')->crop(300, 300, 200, 600); // $img = Image::make('5721fc06d139a.jpg')->fit(400, 200); echo $img->resize(300, 300)->response(null, 52); }
public function options($options = array()) { if ($options) { $this->options = array_merge($this->options, $options); } if (isset($this->options["source"])) { $this->image = Image::make($this->options["source"]); } }
public function avatarupdate(AvatarRequest $request) { Image::make($request->file('avatar'))->resize(196, 180)->encode('jpg')->save(base_path() . '/public/images/avatar/avatar' . Auth::id() . '.jpg'); Image::make($request->file('avatar'))->resize(40, 40)->encode('jpg')->save(base_path() . '/public/images/avatar/30avatar' . Auth::id() . '.jpg'); $user = Auth::user(); $user->avatar = '/images/avatar/avatar' . Auth::id() . '.jpg'; $user->avatar_30 = '/images/avatar/30avatar' . Auth::id() . '.jpg'; $user->save(); return Redirect::back(); }
/** * @param $target * * @return mixed */ public function executeCalls($target) { if (!empty($this->calls)) { $image = ImageManagerStatic::make($target); foreach ($this->calls as $call) { call_user_func_array([$image, $call['method']], $call['arguments'])->save($target); } } return $target; }
/** * * @todo make this better * @return string */ public function downloadImage() { $this->findImage(); $this->setFolder(); $img = Image::make($this->image_uri)->fit(100); $extention = 'jpg'; $filename = $this->folder . '/' . 'image_' . md5(microtime()) . '.' . $extention; $img->save($filename, 60); return $filename; }
/** * @inheritdoc */ public function behaviors() { return ['timestamp' => TimestampBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name'], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedImage' => ['filesystem' => 'local', 'path' => '/categories', 'fileName' => '{model.slug}.{file.extension}', 'relation' => 'image', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) { $image = ImageManagerStatic::make($file->getPath()); $image->resize(400, null, function (Constraint $constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $image->save($file->getPath(), 100); }]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['image' => ['deleteOnUnlink' => true]], 'relations' => ['imageRelation' => $this->hasOne(CategoryFile::className(), ['id' => 'image_id'])]]]; }