简体   繁体   English

在laravel 4中上传svg图像时出现“无法读取图像”错误

[英]“Unable to read image” error while uploading svg image in laravel 4

I have code which working ok for jpg,png images to resize images, here is the code sample. 我有代码,可用于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]}");

This one is working great with jpg and png images, but when i am using svg it will return error like Unable to read image from file . 这个与jpgpng图像一起工作很好,但是当我使用svg ,它将返回错误,如Unable to read image from file Any solution? 有解决方案吗

SVG is not supported by Intervention Image : Intervention Image不支持SVG

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

You can use ImageMagick to work with SVG . 您可以使用ImageMagick来使用SVG

You probably wouldn't want to resize the SVG images. 您可能不希望调整SVG图像的大小。 So the solution will be to get the MIME-TYPE and skip resizing: 所以解决方案是获取MIME-TYPE并跳过调整大小:

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

Basically SVG is stands for the Scalable Vector Graphics it's type is differ from any other image,It is open in to the web Browser so there is different way to integrate Here is the way how to integrate it. 基本上SVG代表可缩放矢量图形,它的类型与任何其他图像不同,它在Web浏览器中是开放的,所以有不同的集成方式以下是如何集成它的方式。

1) Convert an SVG document into a PHP document. 1)将SVG文档转换为PHP文档。 2) Use the object and embed elements to include an SVG document in an XHTML document. 2)使用object和embed元素在XHTML文档中包含SVG文档。 3) Generate SVG using PHP's echo command. 3)使用PHP的echo命令生成SVG。 4) Generate SVG using the phpHtmlLib library. 4)使用phpHtmlLib库生成SVG。 5) Generate SVG documents using the PEAR::XML_SVG package. 5)使用PEAR :: XML_SVG包生成SVG文档。 6) Generate SVG documents using the PEAR::Image_Canvas package. 6)使用PEAR :: Image_Canvas包生成SVG文档。 7) Integrate PHP , SVG, and AJAX. 7)集成PHP,SVG和AJAX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM