问题
Hi I want to save an uploaded image as 2 versions (normal and thumbnail)
Here is the code I'm using for normal:
$picture = Upload::save($_FILES['picture']);
// Resize, sharpen, and save the image
Image::factory($picture)->resize(200, NULL)->save();
$profile->profile_picture = basename($picture);
This works, but I also want to create a smaller version to $profile->profile_picture_thumb.
I have tried just repeating the above process with a a different variable name $picture_thumb = Upload::save($_FILES['picture']);. But that that did not work me.
Any suggestions would be greatly appreciated.
回答1:
Upload::save() returns path to saved file, so just easily create new Image instance from it and save smaller version of Image. Something like:
$picture = Upload::save($_FILES['picture']);
// Resize, sharpen, and save the image
$image = Image::factory($picture)->resize(200, NULL);
$image->save();
$profile->profile_picture = basename($picture);
// Save thumbnail
$thumb_path = dirname($image->file).'/thumb_'.basename($image->file);
Image::factory($picture)->resize(100, NULL)->save($thumb_path);
$profile->profile_picture_thumb = basename($thumb_path);
来源:https://stackoverflow.com/questions/12732221/kohana-3-image-save-and-thumbnail