kohana 3图片保存和缩略图 [英] kohana 3 image save and thumbnail

查看:118
本文介绍了kohana 3图片保存和缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将上传的图像保存为2个版本(普通版和缩略图版)

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);

这可行,但我也想创建一个小于$profile->profile_picture_thumb的较小版本.

This works, but I also want to create a smaller version to $profile->profile_picture_thumb.

我尝试使用不同的变量名称$picture_thumb = Upload::save($_FILES['picture']);重复上述过程.但这对我没有用.

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.

任何建议将不胜感激.

推荐答案

Upload :: save()返回保存文件的路径,因此只需轻松地从中创建新的Image实例并保存较小版本的Image.像这样:

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);

这篇关于kohana 3图片保存和缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆