我正在研究这个Laravel 5.4 Social Network Script,当我发布一些东西时,正在显示头像和#34;动画"但是当它被保存时,它会被转换为静态图像。
我在控制器TimelineController @ createPost:
中有这个...
use App\Media;
use App\Post;
use Intervention\Image\Facades\Image;
...
public function createPost(Request $request)
{
$input = $request->all();
$post = Post::create($input);
...
if ($request->file('post_images_upload_modified')) {
foreach ($request->file('post_images_upload_modified') as $postImage) {
$strippedName = str_replace(' ', '', $postImage->getClientOriginalName());
$photoName = date('Y-m-d-H-i-s').$strippedName;
$avatar = Image::make($postImage->getRealPath());
$avatar->save(storage_path().'/uploads/users/gallery/'.$photoName, 60);
$media = Media::create([
'title' => $photoName,
'type' => 'image',
'source' => $photoName,
]);
$post->images()->attach($media);
}
}
...
}
...
它使用GD Library在内部处理图像。
/vendor/intervention/image/src/Intervention/Image/上的Image.php文件:
- @method \ Intervention \ Image \ Image make(mixed $ source)从源创建新图像实例的通用工厂方法,可以是文件路径,GD图像资源,Imagick对象或二进制图像数据。 / LI>
/**
* Starts encoding of current image
*
* @param string $format
* @param integer $quality
* @return \Intervention\Image\Image
*/
public function encode($format = null, $quality = 90)
{
return $this->driver->encode($this, $format, $quality);
}
/**
* Saves encoded image in filesystem
*
* @param string $path
* @param integer $quality
* @return \Intervention\Image\Image
*/
public function save($path = null, $quality = null)
{
$path = is_null($path) ? $this->basePath() : $path;
if (is_null($path)) {
throw new Exception\NotWritableException(
"Can't write to undefined path."
);
}
$data = $this->encode(pathinfo($path, PATHINFO_EXTENSION), $quality);
$saved = @file_put_contents($path, $data);
if ($saved === false) {
throw new Exception\NotWritableException(
"Can't write image data to path ({$path})"
);
}
// set new file info
$this->setFileInfoFromPath($path);
return $this;
}
存储的图像是GIF,但是尽管未指定,仍会调整大小:
你知道如何保存图像动画吗?