我正在使用 laravel 4.2 的干预/图像模块,上传图片我正在使用此代码:
if (Input::hasFile('image'))
{
$file = Input::file('image');
$file->move('uploads/2/', $file->getClientOriginalName());
$image = Image::make(sprintf('uploads/2/%s', $file->getClientOriginalName()))->resize(120, 120)->save();
return 'yes';
}
对于某些图像,它可以工作,对于某些图像,它会产生此错误:
imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
switch ($info[2]) {
case IMAGETYPE_PNG:
$core = imagecreatefrompng($path);
$this->gdResourceToTruecolor($core);
break;
case IMAGETYPE_JPEG:
$core = imagecreatefromjpeg($path);
$this->gdResourceToTruecolor($core);
break;