";无法读取图像“;在laravel 4中上传svg图像时出错


"Unable to read image" error while uploading svg image in laravel 4

我有一段代码,适用于jpg、png图像来调整图像大小,这是代码示例。

$image = Image::make("{$filePath}/{$fileName[0]}");
// Get the maximum uploaded image width
$maxWidth = Config::get('constants.max_uploaded_image_width');
// Resize the image
$image->resize($maxWidth, null, function($constraint)
{
    // Set an aspect ratio constraint
    $constraint->aspectRatio();
    // Prevent upsizing
    $constraint->upsize();
});
// Save the image
$image->save("{$filePath}/{$fileName[0]}");

这一个在jpgpng图像上工作得很好,但当我使用svg时,它会返回类似Unable to read image from file的错误。有什么解决方案吗?

Intervention Image:不支持SVG

http://image.intervention.io/getting_started/formats

您可以使用ImageMagick来处理SVG

您可能不想调整SVG图像的大小。因此,解决方案将是获得MIME-TYPE并跳过调整大小:

if($image->mime() != 'text/svg+xml') {
    // resize
}

基本上SVG代表可缩放矢量图形,它的类型不同于任何其他图像,它在web浏览器中打开,因此有不同的集成方式。以下是如何集成它的方式。

1) 将SVG文档转换为PHP文档。2) 使用对象和嵌入元素将SVG文档包括在XHTML文档中。3) 使用PHP的echo命令生成SVG。4) 使用phpHtmlLib库生成SVG。5) 使用PEAR::XML_SVG包生成SVG文档。6) 使用PEAR::Image_Canvas包生成SVG文档。7) 集成PHP、SVG和AJAX。