image - Resize to 3 different size at a time to different path using intervention in laravel 5.0 -
i trying resize images in laravel 4.2 using intervention, want move images 2 different folders @ time.
if run below code
if(input::hasfile('product_images')) { $images = input::file('product_images'); foreach($images $image) { if($image->isvalid()) { $file_name = microtime(); $file_name = str_replace(' ', '_', $file_name); $file_name = str_replace('.', '_', $file_name); $file_name = $file_name . '.' . $image->getclientoriginalextension(); $file_name = $image->getclientoriginalextension(); $image->move(public_path() . '/uploads/', $file_name); $file = image::make(sprintf('uploads/%s', $file_name))->resize(800, 600)->save();
it(above code) runs proper uploads folder but, if create folder called thumbnail inside uploads & add below line i'll error as....,
("intervention\image\exception\notreadableexception","message":"image source not readable")........
$file = image::make(sprintf('uploads/thumbnail/%s', $file_name))->resize(75,75)->save();
thanks in advance
the issue above code original file being resized blurry images. can avoided using aspectratio used in below code.
also set memory limit -1. it'll easier upload larger images web page, 30 60 kb , larger.
implementation like:
$imagetype = array( 'thumbnail' => array( 'width' => 50, 'height' => 50 ), 'detail_page' => array( 'width' => 200, 'height' => 200 ), 'product' => array( 'width' => 400, 'height' => 400 ), ); if(request::hasfile('image')) { $image = request::file('image'); if($image->isvalid()) { ini_set('memory_limit', '-1'); $file_name = microtime(); $file_name = str_replace(' ', '_', $file_name); $file_name = str_replace('.', '_', $file_name); $file_name = $file_name . '.' . $image->getclientoriginalextension(); $image->move(public_path() . '/uploads/', $file_name); $response['file_name'] = $file_name; foreach ($imagetype $key => $value) { $file = image::make(sprintf('uploads/%s', $file_name))->resize($value['width'], $value['height'], function($constraint) { $constraint->aspectratio(); }); $file->save(public_path() . '/uploads/'.$value['width'].'x'.$value['height'].'/'. $file_name); } $product_image_url = url::to('uploads/' . $file_name);
Comments
Post a Comment