kohana 3 image save and thumbnail [closed]

柔情痞子 提交于 2019-12-08 13:43:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!