本文整理汇总了PHP中Intervention\Image\Facades\Image类的典型用法代码示例。如果您正苦于以下问题:PHP Image类的具体用法?PHP Image怎么用?PHP Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postAdd
public function postAdd(Request $request, Agent $agent)
{
$data = $request->all();
$validation = Validator::make($data, Poster::getValidationRules());
if ($validation->fails()) {
return view('message', ['OKs' => [], 'errors' => $validation->errors()->all()]);
}
$original_image_dir = 'images/original/';
$small_image_dir = 'images/small/';
$original_image_name = $original_image_dir . "no_image.jpg";
$small_image_name = $small_image_dir . "no_image_sml.jpg";
if ($request->hasFile('image')) {
$time = time();
$original_image_name = $original_image_dir . $time . '.jpg';
$small_image_name = $small_image_dir . $time . '.jpg';
Image::make(Input::file('image'))->save($original_image_name)->resize(200, null, function ($constraint) {
$constraint->aspectRatio();
})->save($small_image_name);
} else {
}
$data['image'] = $original_image_name;
$data['image_sml'] = $small_image_name;
$data['author_ip'] = $request->getClientIp();
$data['author_browser'] = $agent->browser();
$data['author_country'] = "Ukraine";
Poster::create($data);
return view('message', array('OKs' => ['Poster created'], 'errors' => ['']));
}
示例2: findByUserNameOrCreate
public function findByUserNameOrCreate($userData)
{
$user = User::where('social_id', '=', $userData->id)->first();
if (!$user) {
$user = new User();
$user->social_id = $userData->id;
$user->email = $userData->email;
$user->first_name = $userData->user['first_name'];
$user->last_name = $userData->user['last_name'];
$name = str_random(32);
while (!User::where('avatar', '=', $name . '.jpg')->get()->isEmpty()) {
$name = str_random(32);
}
$filename = $name . '.' . 'jpg';
Image::make($userData->avatar_original)->fit(1024, 1024)->save(public_path() . '/avatars_large/' . $filename);
Image::make(public_path() . '/avatars_large/' . $filename)->resize(200, 200)->save(public_path() . '/avatars/' . $filename);
$user->avatar = $filename;
$user->gender = $userData->user['gender'];
$user->verified = $userData->user['verified'];
$user->save();
\Session::put('auth_photo', $filename);
} else {
$this->checkIfUserNeedsUpdating($userData, $user);
\Session::put('auth_photo', $user->avatar);
}
return $user;
}
示例3: update
public function update(Request $request)
{
$user = $request->auth;
$id = $request->route('id');
$uniq = md5(uniqid(time(), true));
if ($request->hasFile('image')) {
$types = array('115x69', '285x170', '617x324');
// Width and height for thumb and resiged
$sizes = array(array('115', '69'), array('285', '170'), array('617', '324'));
$targetPath = 'img/media/';
$image = $request->file('image');
$ext = $image->getClientOriginalExtension();
foreach ($types as $key => $type) {
Image::make($image)->fit($sizes[$key][0], $sizes[$key][1])->save($targetPath . $type . "/" . $uniq . '.' . $ext);
}
}
$post = PostModel::findOrFail($id);
$post->pos_name = ucfirst($request->input('pos_name'));
$post->pos_slug = $request->input('pos_slug');
if ($request->hasFile('image')) {
$post->pos_image = $uniq . '.' . $ext;
}
$post->pos_sum = $request->input('pos_sum');
$post->pos_desc = $request->input('pos_desc');
$post->pos_status_cd = "ACT";
$post->cat_id = $request->input('cat_id');
$post->updated_by = $user->usr_id;
if (!$post->save()) {
return "Error";
}
return Redirect::route('postHome');
}
示例4: putEdit
public function putEdit(Request $request)
{
if (!ACL::hasPermission('awards', 'edit')) {
return redirect(route('awards'))->withErrors(['Você não pode editar os prêmios.']);
}
$this->validate($request, ['title' => 'required|max:45', 'warning' => 'required', 'image' => 'image|mimes:jpeg,bmp,gif,png'], ['title.required' => 'Informe o título do prêmio', 'title.max' => 'O título do prêmio não pode passar de :max caracteres', 'warning.required' => 'Informe o aviso sobre o prêmio', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formato suportado: .png com fundo transparente']);
$award = Awards::find($request->awardsId);
$award->title = $request->title;
$award->warning = $request->warning;
if ($request->image) {
//DELETE OLD IMAGE
if ($request->currentImage != "") {
if (File::exists($this->folder . $request->currentImage)) {
File::delete($this->folder . $request->currentImage);
}
}
$extension = $request->image->getClientOriginalExtension();
$nameImage = Carbon::now()->format('YmdHis') . "." . $extension;
Image::make($request->file('image'))->resize($this->imageWidth, $this->imageHeight)->save($this->folder . $nameImage);
$award->image = $nameImage;
}
$award->save();
$success = "Prêmio editado com sucesso";
return redirect(route('awards'))->with(compact('success'));
}
示例5: uploadTextarea
public static function uploadTextarea($texto, $tipo_midia)
{
$nomeTipo = TipoMidia::findOrFail($tipo_midia)->descricao;
// gravando imagem do corpo da noticia
$dom = new \DOMDocument();
$dom->loadHtml($texto, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$images = $dom->getElementsByTagName('img');
// foreach <img> in the submited message
foreach ($images as $img) {
$src = $img->getAttribute('src');
// if the img source is 'data-url'
if (preg_match('/data:image/', $src)) {
// get the mimetype
preg_match('/data:image\\/(?<mime>.*?)\\;/', $src, $groups);
$mimetype = $groups['mime'];
// Generating a random filename
$filename = md5(uniqid());
$filepath = "uploads/" . $nomeTipo . "/" . $filename . '.' . $mimetype;
// @see http://image.intervention.io/api/
$image = Image::make($src)->encode($mimetype, 100)->save(public_path($filepath));
$new_src = asset($filepath);
$img->removeAttribute('src');
$img->setAttribute('src', $new_src);
}
}
return $dom->saveHTML();
}
示例6: store
/**
* Update the users profile
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = User::find($request->input('user_id'));
$user->name = $request->input('name');
$user->email = $request->input('email');
$user->username = $request->input('username');
if ($request->input('password') != '') {
$user->password = bcrypt($request->input('password'));
}
$user->update();
$company = Company::where('user_id', $request->input('user_id'))->first();
$company->name = $request->input('company_name');
$company->description = $request->input('company_description');
$company->phone = $request->input('company_phone');
$company->email = $request->input('company_email');
$company->address1 = $request->input('company_address');
$company->address2 = $request->input('company_address2');
$company->city = $request->input('company_city');
$company->postcode = $request->input('company_postcode');
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$name = Str::random(25) . '.' . $file->getClientOriginalExtension();
$image = Image::make($request->file('logo')->getRealPath())->resize(210, 113, function ($constraint) {
$constraint->aspectRatio();
});
$image->save(public_path() . '/uploads/' . $name);
$company->logo = $name;
}
$company->update();
flash()->success('Success', 'Profile updated');
return back();
}
示例7: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store($image, $type, $primary_id, $current_link)
{
$image_link = array_key_exists($type, Input::all()) ? Input::file($type) != '' ? '/allgifted-images/' . $type . '/' . $primary_id . '.' . $image->getClientOriginalExtension() : $current_link : $current_link;
array_key_exists($type, Input::all()) ? File::exists(public_path($image_link)) ? File::delete(public_path($image_link)) : null : null;
$image ? Image::make($image)->fit(500, 300)->save(public_path($image_link)) : null;
return $image_link;
}
示例8: makeImage
protected function makeImage($file, $height, $width, $randomFilename, $thumbnail = null)
{
$md5 = md5_file($file->getRealPath());
$img = Image::make($file)->fit($height, $width);
$path = 'images/';
if ($thumbnail != null) {
$path = 'images/thumb/';
}
$image = Images::where('md5_hash', $md5)->first();
if ($image === null or $image->thumbnail_file == null) {
Clockwork::info('Storing on Filesystem');
$img->save(storage_path() . '/app/' . $path . $randomFilename . '.png', 90);
}
if ($image === null and $thumbnail === null) {
Clockwork::info('New Image');
$image = new Images();
$image->user_id = Auth::user()->id;
$image->filename = $file->getClientOriginalName();
$image->file = $randomFilename . '.png';
$image->height = $height;
$image->width = $width;
$image->md5_hash = $md5;
} elseif ($thumbnail != null and $image->thumbnail_file == null) {
Clockwork::info('Thumbnail Updated');
$image->thumbnail_file = $randomFilename . '.png';
}
$image->save();
return $image;
}
示例9: putEdit
public function putEdit(Request $request)
{
if (!ACL::hasPermission('winners2014', 'edit')) {
return redirect(route('winners2014'))->withErrors(['Você não pode editar os ganhadores de 2014.']);
}
$this->validate($request, ['category' => 'required', 'position' => 'required', 'name' => 'required|max:50', 'city' => 'required|max:45', 'state' => 'required|max:2|min:2', 'quantityVotes' => 'required|numeric', 'image' => 'image|mimes:jpeg,bmp,gif,png'], ['category.required' => 'Escolha a categoria', 'position.required' => 'Escolha a posição', 'name.required' => 'Informe o nome do ganhador', 'name.max' => 'O nome do ganhador não pode passar de :max caracteres', 'city.required' => 'Informe o nome da cidade do ganhador', 'city.max' => 'O nome da cidade não pode passar de :max caracteres', 'state.required' => 'Informe o Estado do ganhador', 'state.max' => 'O UF do Estado deve ter apenas :max caracteres', 'state.min' => 'O UF do Estado deve ter apenas :min caracteres', 'quantityVotes.required' => 'Informe a quantidade de votos', 'quantityVotes.numeric' => 'Somente números são aceitos', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formatos suportados: .jpg, .gif, .bmp e .png']);
$winner = WinnersLastYear::find($request->winnersLastYearId);
$winner->category = $request->category;
$winner->position = $request->position;
$winner->name = $request->name;
$winner->city = $request->city;
$winner->state = $request->state;
$winner->quantityVotes = $request->quantityVotes;
if ($request->photo) {
//DELETE OLD PHOTO
if ($request->currentPhoto != "") {
if (File::exists($this->folder . $request->currentPhoto)) {
File::delete($this->folder . $request->currentPhoto);
}
}
$extension = $request->photo->getClientOriginalExtension();
$namePhoto = Carbon::now()->format('YmdHis') . "." . $extension;
$img = Image::make($request->file('photo'));
if ($request->photoCropAreaW > 0 or $request->photoCropAreaH > 0 or $request->photoPositionX or $request->photoPositionY) {
$img->crop($request->photoCropAreaW, $request->photoCropAreaH, $request->photoPositionX, $request->photoPositionY);
}
$img->resize($this->photoWidth, $this->photoHeight)->save($this->folder . $namePhoto);
$winner->photo = $namePhoto;
}
$winner->save();
$success = "Ganhador editado com sucesso";
return redirect(route('winners2014'))->with(compact('success'));
}
示例10: create
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
//Dodavanje slika
if (isset($data['foto'])) {
$image = $data['foto'];
$image_name = $image->getClientOriginalName();
$image->move('img/korisnici', $image_name);
$image_final = 'img/korisnici/' . $image_name;
$int_image = Image::make($image_final);
$int_image->resize(300, null, function ($promenljiva) {
$promenljiva->aspectRatio();
});
$int_image->save($image_final);
} else {
$image_final = 'img/default/slika-korisnika.jpg';
}
//Dodavanje novog grada
if ($data['novi_grad']) {
$pomocna = DB::table('grad')->where('grad.naziv', '=', $data['novi_grad'])->first();
if ($pomocna) {
$data['grad_id'] = $pomocna->id;
} else {
Grad::create(['naziv' => $data['novi_grad']]);
$pomocna = DB::table('grad')->where('grad.naziv', '=', $data['novi_grad'])->first();
$data['grad_id'] = $pomocna->id;
}
}
//Dodavanje novog korisnika
$aktivacioni_kod = str_random(30);
$podaci = array('aktivacioni_kod' => $aktivacioni_kod);
Mail::send('emails.aktiviranje_naloga', $podaci, function ($message) {
$message->to(Input::get('email'), Input::get('username'))->subject('Активирање налога');
});
return User::create(['prezime' => $data['prezime'], 'ime' => $data['ime'], 'password' => bcrypt($data['password']), 'username' => $data['username'], 'email' => $data['email'], 'adresa' => $data['adresa'], 'grad_id' => $data['grad_id'], 'telefon' => $data['telefon'], 'opis' => $data['bio'], 'foto' => $image_final, 'aktivacioni_kod' => $aktivacioni_kod, 'token' => $data['_token']]);
}
示例11: __construct
/**
* Create a new UploadImageAbstract instance
*
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
*/
public function __construct($file)
{
$this->file = $file;
$this->hash = mt_rand(1000000000, 4294967295);
$this->image = InterventionImage::make($this->file);
$this->uploaded_at = Carbon::now();
}
示例12: create
public function create(Offer $offer, Request $request)
{
if ($request->user()->cannot('edit-offer', [$offer])) {
abort(403);
}
$this->validate($request, ['title' => 'required', 'image' => 'required|image', 'expired_at' => 'required']);
$user = Auth::user();
// wildcard is needed
$offer = $user->offers()->where('id', $offer->id)->where('status', 1)->valid()->firstOrFail();
$input = $request->all();
$data = $request->input('cropper_json');
$data = json_decode(stripslashes($data));
$image = $input['image'];
$imageName = $user->id . str_random(20) . "." . $image->getClientOriginalExtension();
$image->move(public_path() . '/img/files/' . $user->id, $imageName);
$src = public_path() . '/img/files/' . $user->id . '/' . $imageName;
$img = Image::make($src);
$img->rotate($data->rotate);
$img->crop(intval($data->width), intval($data->height), intval($data->x), intval($data->y));
$img->resize(851, 360);
$img->save($src, 90);
$service = $user->coupon_gallery()->create(['offer_id' => $offer->id, 'title' => $input['title'], 'description' => $input['description'], 'expired_at' => $input['expired_at'], 'image' => $user->id . "/" . $imageName]);
Flash::success(trans('messages.offerCreated'));
$user->usage->add(filesize(public_path() . '/img/files/' . $user->id . '/' . $imageName) / (1024 * 1024));
// storage add
return redirect()->back();
}
示例13: show
/**
* Display the specified resource.
*
* @param $image_slug
* @param int $width
* @return Response
*/
public function show($image_slug, $width = 500)
{
$currentUser = $this->getUser();
//$size = (Input::get('size')? (is_numeric(Input::get('size'))? Input::get('size') : 500) : 500);//TODO: Extract this to global config
$comicImage = ComicImage::where('image_slug', '=', $image_slug)->first();
if (!$comicImage) {
return $this->respondNotFound(['title' => 'Image Not Found', 'detail' => 'Image Not Found', 'status' => 404, 'code' => '']);
}
$userCbaIds = $currentUser->comics()->lists('comic_book_archive_id')->all();
$comicCbaIds = $comicImage->comicBookArchives()->lists('comic_book_archive_id')->all();
foreach ($comicCbaIds as $comicCbaId) {
if (!in_array($comicCbaId, $userCbaIds)) {
return $this->respondNotFound(['title' => 'Image Not Found', 'detail' => 'Image Not Found', 'status' => 404, 'code' => '']);
}
}
$img = Image::make($comicImage->image_url);
$imgCache = Image::cache(function ($image) use($img, $width) {
$image->make($img)->interlace()->resize(null, $width, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
}, 60, true);
//dd($imgCache->response());
return $imgCache->response();
}
示例14: uploadPhoto
public function uploadPhoto($userId, $filePath, $newImage = false)
{
$tmpFilePath = storage_path('app') . '/' . $userId . '.png';
$tmpFilePathThumb = storage_path('app') . '/' . $userId . '-thumb.png';
try {
$this->correctImageRotation($filePath);
} catch (\Exception $e) {
\Log::error($e);
//Continue on - this isnt that important
}
//Generate the thumbnail and larger image
Image::make($filePath)->fit(500)->save($tmpFilePath);
Image::make($filePath)->fit(200)->save($tmpFilePathThumb);
if ($newImage) {
$newFilename = \App::environment() . '/user-photo/' . md5($userId) . '-new.png';
$newThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb-new.png';
} else {
$newFilename = \App::environment() . '/user-photo/' . md5($userId) . '.png';
$newThumbFilename = \App::environment() . '/user-photo/' . md5($userId) . '-thumb.png';
}
Storage::put($newFilename, file_get_contents($tmpFilePath), 'public');
Storage::put($newThumbFilename, file_get_contents($tmpFilePathThumb), 'public');
\File::delete($tmpFilePath);
\File::delete($tmpFilePathThumb);
}
示例15: __toString
public function __toString()
{
if ($this->isSkip) {
return '';
}
$methodsHash = md5(serialize($this->methods));
$hash = md5($this->fileHash . $methodsHash);
$source = 'storage/cropp/' . $hash . $this->extension;
if (is_readable(public_path($source))) {
return $source;
}
$image = Image::make($this->source);
foreach ($this->methods as $method) {
call_user_func_array(array($image, $method['name']), $method['arguments']);
}
$res = $image->save(public_path($source));
if (!$res) {
throw new RuntimeException('Do you have writeable [public/storage/cropp/] directory?');
}
if (\Config::get('jarboe::cropp.is_optimize')) {
$optimizer = new \Extlib\ImageOptimizer(array(\Extlib\ImageOptimizer::OPTIMIZER_OPTIPNG => \Config::get('jarboe::cropp.binaries.optipng'), \Extlib\ImageOptimizer::OPTIMIZER_JPEGOPTIM => \Config::get('jarboe::cropp.binaries.jpegoptim'), \Extlib\ImageOptimizer::OPTIMIZER_GIFSICLE => \Config::get('jarboe::cropp.binaries.gifsicle')));
$optimizer->optimize(public_path($source));
}
return $source;
}