【问题标题】:kohana 3 image save and thumbnail [closed]kohana 3图像保存和缩略图[关闭]
【发布时间】:2012-09-25 18:45:35
【问题描述】:

您好,我想将上传的图片保存为 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']); 重复上述过程。但这对我不起作用。

任何建议将不胜感激。

【问题讨论】:

  • “不起作用”不是有效的错误消息。

标签: php kohana image-uploading


【解决方案1】:

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

【讨论】:

  • 缩略图文件没有保存,但是db条目在那里
  • 不,现在我收到错误 ErrorException [注意]:尝试获取非对象的属性
  • 我明白了。这是因为 save 只返回 bool 而不是 Upload::save 的路径。现在已经修好了,现在可以用了吗? :)
  • 谢谢您,先生!非常感谢并会从中学习
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-27
相关资源
最近更新 更多