我正在尝试制作保存图像缩略图和原始图像的功能。目的是在页面上显示较小的版本,以便页面加载速度快,当用户点击图像时,原件将打开到灯箱中。
我正在使用php-image-resize。这就是我迄今为止所尝试过的以及迄今为止我所拥有的。
public function uploadSubmit() {
$file = Input::file('image');
$image = new ImageResize($file);
$gallery = new Gallery;
$filename = str_random(20) . '.' . $file->getClientOriginalExtension();
$thumb = $filename . '-thumb.' . $file->getClientOriginalExtension();
$file->move('uploads', $filename);
$imagePath = '/uploads/' . $filename;
$image->crop(200, 200);
$image->save('/uploads/' . $thumb);
$gallery->image = $imagePath;
$gallery->image_path = $image;
$gallery->image_name = strip_tags(Input::get('image_name'));
$gallery->save();
return Redirect::to('/admin/upload')->with('message', 'Image added.');
}
当我运行页面时,我收到了错误
消息'imagejpeg(/uploads/44Bsl9HybTvFLpKIYcdL.jpg-thumb.jpg)的'ErrorException':无法打开流:没有这样的文件或目录'
应裁剪图像的部分是
$image = new ImageResize($file);
$thumb = $filename . '-thumb.' . $file->getClientOriginalExtension();
$image->crop(200, 200);
$image->save('/uploads/' . $thumb);
感谢任何帮助。
更新:工作源
$file = Input::file('image');
$image = new ImageResize($file);
$gallery = new Gallery;
$filename = str_random(20);
$original = $filename . '.'. $file->getClientOriginalExtension();
$thumb = $filename . '-thumb.' . $file->getClientOriginalExtension();
$file->move('uploads', $original);
$imagePath = 'uploads/' . $original;
$thumbPath = 'uploads/' . $thumb;
$image->crop(200, 200);
$image->save('uploads/' . $thumb);
$gallery->image = $imagePath;
$gallery->image_path = $thumbPath;
$gallery->image_name = strip_tags(Input::get('image_name'));
$gallery->save();