0

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

这是我正常使用的代码:

$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.

我试过用不同的变量名重复上述过程$picture_thumb = Upload::save($_FILES['picture']);。但这对我不起作用。

任何建议将不胜感激。

4

1 回答 1

2

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

$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);
于 2012-10-04T17:20:42.877 回答