【问题标题】:"Unable to read image" error while uploading svg image in laravel 4在 laravel 4 中上传 svg 图像时出现“无法读取图像”错误
【发布时间】:2016-07-13 22:31:32
【问题描述】:

我的代码可以用于 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 的错误。有什么解决办法吗?

【问题讨论】:

    标签: php laravel svg laravel-4 gd


    【解决方案1】:

    Intervention Image 不支持SVG

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

    您可以使用ImageMagickSVG 一起工作。

    【讨论】:

    • 但我不想转换为 png,我想要 svg 格式。有什么解决办法吗?
    【解决方案2】:

    您可能不想调整 SVG 图像的大小。所以解决方案是获取 MIME-TYPE 并跳过调整大小:

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

    【讨论】:

      【解决方案3】:

      基本上 SVG 是 Scalable Vector Graphics 的代表,它的类型不同于任何其他图像,它对 Web 浏览器是开放的,因此有不同的集成方式 这里是如何集成它的方式。

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

      【讨论】:

        猜你喜欢
        • 2011-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-13
        • 2018-01-06
        • 2017-05-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多