kohana 3.0 resize image before uploading?
I want to upload some images to the server, but first of all i want them croped, and resized to some certain dimensions.
Now i am doing the simple upload and save like that:
$header_image = Upload::save($_FILES['sale_picture_header'],NULL,APPPATH.'media'.'/');
$image_header = Model::factory('image');
$image_header->name = basename($header_image);
$image_header->save();
(excluding the validation).
Ho开发者_如何学Gow can i crop or resize the image to some desired dimensions, in Kohana 3.0? I couldn't find any relevant documentation regarding that.
Thank you!
Did you try with the image package:
// Resize to 200 pixels on the shortest side
$image->resize(200, 200);
// Resize to 200x200 pixels, keeping aspect ratio
$image->resize(200, 200, Image::INVERSE);
// Resize to 500 pixel width, keeping aspect ratio
$image->resize(500, NULL);
// Resize to 500 pixel height, keeping aspect ratio
$image->resize(NULL, 500);
// Resize to 200x500 pixels, ignoring aspect ratio
$image->resize(200, 500, Image::NONE);
source: http://kohanaframework.org/3.0/guide/api/Image#resize
You can use the ImageMagick library, or the GD library for image manipulation.
Also note that these are strictly server-side, and will not happen before upload. For that you'd need some client-side plugin capable of image manipulation such as Flash or Java.
I found something very interesting. The question was, how to perform this action, "resize then crop" an image to fit perfectly a determined box, and this is the solution:
Image::factory($file)
->resize(128, 149, Image::PRECISE)
->crop(128, 149)
->save(DOCROOT.$filename);
Note that you must use Image::PRECISE, instead of IMAGE::AUTO.
Hope this helps someone.
精彩评论