Imagick / imagick

🌈 The Imagick PHP extension 🌈
http://pecl.php.net/imagick
Other
548 stars 138 forks source link

Convert SVG to JPG/PNG #614

Open wojoj93 opened 1 year ago

wojoj93 commented 1 year ago

hi, I have a problem with converting svg file to jpg/png via imagick: here is code:

$image = new \Imagick(); $image->readImage('old.svg'); $image->setImageFormat('png'); $image->setImageCompressionQuality(100); $image->writeImage('new.png'); $image->destroy();

result: SVG: Zaznaczenie_1210 PNG/JPG: Zaznaczenie_1211

Could someone tell me what I do wrong?

Danack commented 1 year ago

Can you provide the original SVG as an svg, rather than the PNG that is appears to be on github?

Also, can you say how you installed Imagick please?

wojoj93 commented 1 year ago

Thank you for your reply. Here is an original svg: qr

Installation process:

Imagick

RUN apt-get install -y libmagickwand-dev \ && pecl install imagick \ && docker-php-ext-enable imagick COPY imagick/policy.xml /etc/ImageMagick-6/policy.xml

Danack commented 1 year ago

Okay, I get the same error using Imagick/ImageMagick.

I'd suggest opening an issue at their repo here: https://github.com/ImageMagick/ImageMagick6

However....you probably just want to get your stuff working.

There have been so many SVG problems with ImageMagick, I pretty strongly recommend using Inkscape to convert files instead of Imagick/ImageMagick.

inkscape can be install through apt and then to convert a file, it needs to be invoked with something like:

inkscape "old.svg" --export-filename="./output_inkscape_directly.png" \
  --export-dpi="96" \
  --export-background="white" \
  --export-background-opacity="255" > inkscape_output.txt 2>&1

I should probably write this down in the docs.

Inkscape is a dedicated SVG converter, it's always going to be more reliable than ImageMagick, where the maintainers have many other things to worry about.