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


PHP Image::make方法代码示例

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


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

示例1: update

 public function update()
 {
     $rules = array('name' => 'required', 'desc' => 'required', 'totalposts' => 'required|numeric');
     $validator = Validator::make(Input::all(), $rules);
     $badgeid = Input::get('id');
     if ($validator->fails()) {
         return Redirect::to('admin/editbadge/' . $badgeid)->withErrors($validator)->withInput();
     } else {
         $name = Input::get('name');
         if (Input::get('badge')) {
             $image = explode('/', Input::get('badge'));
             $image = urldecode(end($image));
             $extension = explode(".", $image);
             $extension = end($extension);
             $img = Image::make('files/' . $image);
             $img->resize(160, null, function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             })->save('files/' . $image);
             $newname = date('YmdHis') . '_' . Str::slug($name, '_') . '.' . $extension;
             File::move('files/' . $image, 'badges/' . $newname);
         }
         $badge = Badge::find($badgeid);
         $badge->name = Input::get('name');
         $badge->description = Input::get('desc');
         if (Input::get('badge')) {
             $badge->image = $newname;
         }
         $badge->total_posts = Input::get('totalposts');
         $badge->save();
         Session::flash('success', 'Badge updated');
         return Redirect::to('admin/badges');
     }
 }
开发者ID:ChavezRuston,项目名称:fansemo,代码行数:34,代码来源:BadgeController.php

示例2: boot

 public static function boot()
 {
     parent::boot();
     static::deleting(function ($photo) {
         $photo->galleries()->detach($photo->id);
         return true;
     });
     static::deleted(function ($photo) {
         unlink(public_path() . \Config::get('laravel-photogallery::upload_dir') . '/' . $photo->path);
         $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/";
         $formats = \Config::get('laravel-photogallery::formats');
         foreach ($formats as $name => $format) {
             unlink($destination . $name . '/' . $photo->path);
         }
     });
     static::created(function ($photo) {
         $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/";
         $orig = $destination . $photo->path;
         $img = \Image::make($orig);
         $formats = \Config::get('laravel-photogallery::formats');
         foreach ($formats as $name => $format) {
             $img->resize($format['w'], $format['h'], function ($constraint) {
                 $constraint->aspectRatio();
             });
             $img->save($destination . $name . '/' . $photo->path, $format['q']);
         }
     });
 }
开发者ID:itestense,项目名称:laravel-photogallery,代码行数:28,代码来源:Photo.php

示例3: store

 public function store()
 {
     //存储数据
     $market = new Market();
     $market->title1 = $this->request->get('title1');
     $market->sc_price = $this->request->get('sc_price');
     $market->cb_price = $this->request->get('cb_price');
     $market->desc = $this->request->get('desc');
     $market->amount = $this->request->get('amount');
     $market->rank = $this->request->get('rank');
     $market->alibaba1 = $this->request->get('alibaba1');
     $market->alibaba2 = $this->request->get('alibaba2');
     $market->investigators = $this->request->get('investigators');
     $market->save();
     //获取图片
     $images = $this->request->file('images');
     foreach ($images as $image) {
         //获取图片名称
         $fileName = md5(uniqid(str_random(10)));
         //
         try {
             \Image::make($image)->resize(100, 100)->save('uploads/images/' . $fileName . '.jpg');
             //存储图片
             $marketImage = new MarketImage();
             $marketImage->image = 'uploads/images/' . $fileName . '.jpg';
             $marketImage->market_id = $market->id;
             $marketImage->save();
         } catch (\Exception $e) {
             //图片上传失败
             dd($e->getMessage());
         }
     }
     //通过循环存储照片
 }
开发者ID:abcn,项目名称:jxc,代码行数:34,代码来源:MarketController.php

示例4: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $id = Auth::user()->ID;
     $files = Input::file('files');
     $assetPath = '/uploads/' . $id;
     $uploadPath = public_path($assetPath);
     $results = array();
     foreach ($files as $file) {
         if ($file->getSize() > $_ENV['max_file_size']) {
             $results[] = array("name" => $file->getClientOriginalName(), "size" => $file->getSize(), "error" => "Please upload file less than " . $_ENV['max_file_size'] / 1000000 . "mb");
         } else {
             //rename filename so that it won't overlap with existing file
             $extension = $file->getClientOriginalExtension();
             $filename = time() . Str::random(20) . "." . $extension;
             // store our uploaded file in our uploads folder
             $name = $assetPath . '/' . $filename;
             $photo_attributes = array('name' => $filename, 'size' => $file->getSize(), 'url' => asset($name), 'user_id' => $id);
             $photo = new Photo($photo_attributes);
             if ($photo->save()) {
                 if (!is_dir($uploadPath)) {
                     mkdir($uploadPath, 0777);
                 }
                 //resize image into different sizes
                 foreach (Photo::getThumbnailSizes() as $key => $thumb) {
                     Image::make($file->getRealPath())->resize($thumb['width'], $thumb['height'])->save($uploadPath . "/" . $key . "-" . $filename);
                 }
                 //save original file
                 $file->move($uploadPath, $filename);
                 $results[] = Photo::find($photo->id)->find_in_json();
             }
         }
     }
     // return our results in a files object
     return json_encode(array('files' => $results));
 }
开发者ID:shankargiri,项目名称:Quantum-Vic-La-Trobe-L4,代码行数:40,代码来源:PhotosController.php

示例5: addProduct

 public function addProduct()
 {
     $id = \Input::get('id');
     $rules = array('name' => 'required', 'quantity' => 'required|numeric', 'image' => 'image|mimes:jpeg,jpg,png,gif');
     $input = \Input::all();
     $valid = Validator::make($input, $rules);
     if ($valid->fails()) {
         return \Redirect::back()->withErrors($valid);
     } else {
         // If validation success
         $name = \Input::get('name');
         $quantity = \Input::get('quantity');
         $image = \Input::file('image');
         $product = $id ? Products::find($id) : new Products();
         // Creating product elobquent object
         // If image selected
         if ($image) {
             $filename = time() . "-" . $image->getClientOriginalName();
             $path = 'assets/images/' . $filename;
             \Image::make($image->getRealPath())->resize(200, 200)->save($path);
             $existingImage = '/assets/images/' . $product->image;
             if (file_exists($existingImage)) {
                 \File::delete($existingImage);
             }
             $product->image = $filename;
         }
         $product->name = $name;
         $product->quantity = $quantity;
         $product->save();
         return redirect(action('ProductController@product'));
     }
 }
开发者ID:sujithma,项目名称:shopherebackend,代码行数:32,代码来源:ProductController.php

示例6: update

 public function update($id)
 {
     if (Auth::id() != $id) {
         return Redirect::to('http://google.com');
     }
     $user = Auth::User();
     $validator = Validator::make(Input::all(false), ['email' => 'required|email|unique:users,email,' . $id, 'password' => 'min:5|confirmed:password_confirmation', 'first_name' => 'required', 'last_name' => 'required']);
     if ($validator->passes()) {
         $img_ava = $user->avatar_img;
         $password = Input::get('password');
         if (Input::hasFile('avatar_img')) {
             if (File::exists(Config::get('user.upload_user_ava_directory') . $img_ava)) {
                 File::delete(Config::get('user.upload_user_ava_directory') . $img_ava);
             }
             if (!is_dir(Config::get('user.upload_user_ava_directory'))) {
                 File::makeDirectory(Config::get('user.upload_user_ava_directory'), 0755, true);
             }
             $img = Image::make(Input::file('avatar_img'));
             $img_ava = md5(Input::get('username')) . '.' . Input::file('avatar_img')->getClientOriginalExtension();
             if ($img->width() < $img->height()) {
                 $img->resize(100, null, function ($constraint) {
                     $constraint->aspectRatio();
                 })->crop(100, 100)->save(Config::get('user.upload_user_ava_directory') . $img_ava, 90);
             } else {
                 $img->resize(null, 100, function ($constraint) {
                     $constraint->aspectRatio();
                 })->crop(100, 100)->save(Config::get('user.upload_user_ava_directory') . $img_ava, 90);
             }
         }
         $user->update(['username' => null, 'email' => Input::get('email'), 'password' => !empty($password) ? Hash::make($password) : $user->password, 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name')]);
         return Redirect::back()->with('success_msg', Lang::get('messages.successupdate'));
     } else {
         return Redirect::back()->withErrors($validator)->withInput();
     }
 }
开发者ID:rezadaulay,项目名称:bankupu,代码行数:35,代码来源:SessionController.php

示例7: setImageAttribute

 /**
  * Upload the image while creating/updating records
  * @param File Object $file
  */
 public function setImageAttribute($file)
 {
     // Only if a file is selected
     if ($file) {
         File::exists(public_path() . '/uploads/') || File::makeDirectory(public_path() . '/uploads/');
         File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
         File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path);
         $file_name = $file->getClientOriginalName();
         $file_ext = File::extension($file_name);
         $only_fname = str_replace('.' . $file_ext, '', $file_name);
         $file_name = $only_fname . '_' . str_random(8) . '.' . $file_ext;
         $image = Image::make($file->getRealPath());
         if (isset($this->attributes['folder'])) {
             // $this->attributes['folder'] = Str::slug($this->attributes['folder'], '_');
             $this->images_path = $this->attributes['folder'] . '/';
             $this->thumbs_path = $this->images_path . '/thumbs/';
             File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
             File::exists(public_path() . '/' . $this->thumbs_path) || File::makeDirectory(public_path() . '/' . $this->thumbs_path);
         }
         if (isset($this->attributes['image'])) {
             // Delete old image
             $old_image = $this->getImageAttribute();
             File::exists($old_image) && File::delete($old_image);
         }
         if (isset($this->attributes['thumbnail'])) {
             // Delete old thumbnail
             $old_thumb = $this->getThumbnailAttribute();
             File::exists($old_thumb) && File::delete($old_thumb);
         }
         $image->save(public_path($this->images_path . $file_name))->fit(150, 150)->save(public_path($this->thumbs_path . $file_name));
         $this->attributes['image'] = "{$this->attributes['folder']}/{$file_name}";
         $this->attributes['thumbnail'] = "{$this->attributes['folder']}/thumbs/{$file_name}";
         unset($this->attributes['folder']);
     }
 }
开发者ID:doptor,项目名称:doptor,代码行数:39,代码来源:MediaEntry.php

示例8: update

 public function update($id)
 {
     $setting = Setting::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Setting::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     unset($data['logo']);
     // Logo Image Upload
     if (Input::hasFile('logo')) {
         $path = public_path() . "/assets/admin/layout/img/";
         File::makeDirectory($path, $mode = 0777, true, true);
         $image = Input::file('logo');
         $extension = $image->getClientOriginalExtension();
         $filename = "logo.{$extension}";
         $filename_big = "logo-big.{$extension}";
         Image::make($image->getRealPath())->save($path . $filename);
         Image::make($image->getRealPath())->save($path . $filename_big);
         $data['logo'] = $filename;
     }
     $currencyArray = explode(':', $data['currency']);
     $data['currency'] = $currencyArray[1];
     $data['currency_icon'] = $currencyArray[0];
     $setting->update($data);
     Session::flash('success', '<strong>Success! </strong>Updated Successfully');
     return Redirect::route('admin.settings.edit', 'setting');
 }
开发者ID:rodrigopbel,项目名称:ong,代码行数:27,代码来源:SettingsController.php

示例9: store

 public function store()
 {
     $rules = array("nombre" => "required", "descripcion" => "required");
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::to("categoriasNegocios")->withErrors($validator)->withInput(Input::except("banner"));
     } else {
         $categoria = CategoriasNegocio::create(Input::all());
         if (Input::hasFile('icono')) {
             $file = Input::file('icono');
             $extension = $file->getClientOriginalExtension();
             $name = $file->getClientOriginalName();
             $name = basename($name, ".png");
             $path = public_path() . '/img/emblemas/categorias';
             $image = Image::make(Input::file('icono')->getRealPath());
             $image->fit(96, 96);
             //3x
             $filename3x = $name . '@3x.' . $extension;
             $image->save($path . '/' . $filename3x);
             $categoria->icono_emblema = $filename3x;
         }
         $categoria->save();
     }
     return Redirect::route('categoriasNegocios.show', $categoria->id);
 }
开发者ID:edgarhumberto,项目名称:Prueba,代码行数:25,代码来源:CategoriasNegociosController.php

示例10: attachResize

 public function attachResize($w, $h, $crop = false)
 {
     try {
         $filename = $this->attachGetPath();
         $resized_filename = str_replace($this->app['config']->get('attach.root'), $this->app['config']->get('attach.resized_path'), dirname($filename)) . DIRECTORY_SEPARATOR . $w . 'z' . $h . '_' . ($crop ? 'crop' : 'full') . '_' . basename($filename);
         if (!file_exists($resized_filename)) {
             \Log::info('resizing', ['browsify' => true]);
             $img = \Image::make($filename);
             if ($crop) {
                 $img->fit($w, $h);
             } else {
                 $img->resize($w, $h, function ($constraint) {
                     $constraint->aspectRatio();
                 });
             }
             if (!file_exists(dirname($resized_filename))) {
                 $this->app['files']->makeDirectory(dirname($resized_filename), 0755, true, true);
             }
             $img->save($resized_filename);
         }
         return $resized_filename;
     } catch (\Exception $e) {
         return '/images/noimage.gif';
     }
 }
开发者ID:skvn,项目名称:crud,代码行数:25,代码来源:ModelAttachedTrait.php

示例11: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(PostProductRequest $request)
 {
     if (!$request['category_id'] == '') {
         if (Auth::user()->role == 'free' && Auth::user()->product()->count() < $this->max_product_free) {
             $file = $request->file('image');
             $extension = $file->getClientOriginalExtension();
             $this->validate($request, ['image' => 'image']);
             $date = Carbon::now('America/Sao_Paulo');
             $expired = $date->addMonth();
             $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'expired_at' => $expired]);
             $filename = $product->slug . '-' . time() . '.' . $extension;
             $product->update(['image' => $filename]);
             \Image::make($file)->resize(253, 337)->save('uploads/products/253x337/' . $filename);
             \Image::make($file)->resize(450, 678)->save('uploads/products/450x678/' . $filename);
             Session::flash('message', 'Voc&ecirc; cadastrou um produto com sucesso!');
             return redirect()->route('dashboard.product.index');
         } elseif (Auth::user()->role == 'standart' && Auth::user()->product()->count() < $this->max_product_standart) {
             $file = $request->file('image');
             $extension = $file->getClientOriginalExtension();
             $this->validate($request, ['image' => 'image']);
             $date = Carbon::now('America/Sao_Paulo');
             $expired = $date->addMonth()->addMonth();
             $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'expired_at' => $expired]);
             $filename = $product->id . '-' . $product->slug . '-' . time() . '.' . $extension;
             $product->update(['image' => $filename]);
             Storage::disk('public_local')->put($filename, File::get($file));
             Session::flash('message', 'Voc&ecirc; cadastrou um produto com sucesso!');
             return redirect()->route('dashboard.product.index');
         } elseif (Auth::user()->role == 'premium' && Auth::user()->product()->count() < $this->max_product_premium) {
             $file = $request->file('image');
             $extension = $file->getClientOriginalExtension();
             $this->validate($request, ['image' => 'image']);
             $date = Carbon::now('America/Sao_Paulo');
             $expired = $date->addMonth()->addMonth()->addMonth();
             $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'featured' => '1', 'expired_at' => $expired]);
             $filename = $product->id . '-' . $product->slug . '-' . time() . '.' . $extension;
             $product->update(['image' => $filename]);
             Storage::disk('public_local')->put($filename, File::get($file));
             Session::flash('message', 'Voc&ecirc; cadastrou um produto com sucesso!');
             return redirect()->route('dashboard.product.index');
         } elseif (Auth::user()->role == 'admin') {
             $file = $request->file('image');
             $extension = $file->getClientOriginalExtension();
             $this->validate($request, ['image' => 'image']);
             $date = Carbon::now('America/Sao_Paulo');
             $expired = $date->addMonth();
             $product = Product::create(['category_id' => $request['category_id'], 'user_id' => $request['user_id'], 'name' => $request['name'], 'price' => $request['price'], 'expired_at' => $expired]);
             $filename = $product->id . '-' . $product->slug . '-' . time() . '.' . $extension;
             $product->update(['image' => $filename]);
             Storage::disk('public_local')->put($filename, File::get($file));
             Session::flash('message', 'Voc&ecirc; cadastrou um produto com sucesso!');
             return redirect()->route('dashboard.product.index');
         } else {
             Session::flash('error', "Voc&ecirc; não pode cadastrar mais produtos!");
             return redirect()->route('dashboard.home');
         }
     }
     Session::flash('error', 'Voc&ecirc; não pode cadastrar um produto sem categoria!');
     return redirect()->route('dashboard.product.index');
 }
开发者ID:matheusgomes17,项目名称:farejaofertas,代码行数:66,代码来源:AdminProductController.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($gallery_id)
 {
     $input = \Input::all();
     $validation = new \Itestense\LaravelPhotogallery\Validators\Photo();
     if ($validation->passes()) {
         $filename = str_random(10) . time() . "." . \Input::file('path')->getClientOriginalExtension();
         $destination = public_path() . \Config::get('upload_dir') . "/";
         $upload = \Input::file('path')->move($destination, $filename);
         $img = \Image::make($destination . $filename);
         $formats = \Config::get('laravel-photogallery::formats');
         foreach ($formats as $name => $format) {
             $img->resize($format['w'], $format['h'], function ($constraint) {
                 $constraint->aspectRatio();
             });
             $img->save($destination . $name . '/' . $filename, $format['q']);
         }
         if ($upload == false) {
             return \Redirect::to('gallery.photo.create')->withInput()->withErrors($validation->errors)->with('message', 'Errori');
         }
         $photo = new Photo();
         $photo->name = \Input::get('name');
         $photo->description = \Input::get('description');
         $photo->path = $filename;
         $photo->save();
         $g = Gallery::findOrFail(1);
         $photo->galleries()->attach($g);
         //return \Redirect::route("gallery.photo.show", array('id' => $photo->id));
     } else {
         return \Redirect::route('gallery.photo.create')->withInput()->withErrors($validation->errors)->with('message', \Lang::get('gallery::gallery.errors'));
     }
 }
开发者ID:itestense,项目名称:laravel-photogallery,代码行数:36,代码来源:GalleryPhotosController.php

示例13: update

 public function update(Request $request)
 {
     $id = Auth::user()->id;
     $user = User::findOrFail($id);
     $this->validate($request, ['name' => 'min:5', 'email' => 'min:5', 'image' => 'mimes:jpg,jpeg,png|max:1000']);
     $input['name'] = $request->get('name');
     $input['email'] = $request->get('email');
     if ($request->file('image') != NULL) {
         $image_extension = $request->file('image')->getClientOriginalExtension();
         $image_name = $id;
         $input['avatar'] = $image_name . '.' . $image_extension;
         $destinationFolder = '/admin/assets/images/avatar/';
         $destinationThumbnail = '/admin/assets/images/avatar/thumbs/';
         if (isset($user->avatar)) {
             $avatars = array(public_path() . $destinationFolder . $user->avatar, public_path() . $destinationThumbnail . $user->avatar);
             \File::delete($avatars);
         }
         $user->fill($input)->save();
         $file = \Input::file('image');
         $image = \Image::make($file->getRealPath());
         $image->save(public_path() . $destinationFolder . $image_name . '.' . $image_extension)->resize(60, 60)->save(public_path() . $destinationThumbnail . $image_name . '.' . $image_extension);
     }
     $user->update($input);
     \Session::flash('flash_message', 'Профилът ви беше успешно редактиран!');
     return redirect()->route('admin.user.edit');
 }
开发者ID:mish0501,项目名称:exams,代码行数:26,代码来源:UserController.php

示例14: postCreate

 public function postCreate()
 {
     $validator = Validator::make(Input::all(), Car::$rules);
     if ($validator->passes()) {
         $car = new Car();
         $car->type_id = Input::get('type_id');
         $car->title = Input::get('title');
         if (Input::get('description')) {
             $car->description = Input::get('description');
         }
         $car->price = Input::get('price');
         $car->available_at = Input::get('available_at');
         $car->transmission = Input::get('transmission');
         $car->aircon = Input::get('aircon');
         $car->seats = Input::get('seats');
         $car->doors = Input::get('doors');
         $image = Input::file('image');
         $filename = date('Y-m-d-H:i:s') . "-" . $image->getClientOriginalName();
         Image::make($image->getRealPath())->resize(220, 128)->save('public/img/cars/' . $filename);
         $car->image = 'img/cars/' . $filename;
         $car->save();
         return Redirect::to('admin/cars/index')->with('message', 'New Car Added');
     }
     return Redirect::to('admin/cars/index')->with('message', 'Something went wrong')->withErrors($validator)->withInput();
 }
开发者ID:madiarsa,项目名称:laravel-4.1-car-rental-site,代码行数:25,代码来源:CarsController.php

示例15: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['desc' => 'required', 'desc2' => 'required', 'image' => 'required', 'onlymembers' => 'required', 'img_album_id' => 'required']);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     } else {
         $newImg = new Img();
         $newImg->desc = $request->input('desc');
         $newImg->desc2 = $request->input('desc2');
         $newImg->onlymembers = $request->input('onlymembers');
         $newImg->img_album_id = $request->input('img_album_id');
         $album = ImgAlbum::findOrFail($newImg->img_album_id);
         $file = $request->file('image');
         $image = \Image::make($request->file('image'));
         if ($file != null) {
             if ($file->isValid()) {
                 $name = $newImg->desc . '.' . $file->getClientOriginalExtension();
                 $path = 'img/album/' . $album->id;
                 $file->move($path, $name);
                 $image->fit(100, 50);
                 $image->save($path . '/thumb/' . $name);
                 $newImg->imgurl = $name;
             } else {
                 //dd ('Imagen invalida');
             }
         } else {
             // dd ('No hay Imagen');
         }
         $newImg->save();
     }
     Session::flash('message', 'Album creado correctamente');
     return Redirect::to('/administration/image');
 }
开发者ID:Jorgeachaar,项目名称:Krito,代码行数:38,代码来源:ImageAlbumController.php


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