Skip to content
Advertisement

Strange cropping issue while converting svg to png using Imagick in PHP

I am trying to convert a bunch of svg images into png. Below is the snippet of the Imagick part:

JavaScript

This mostly works as expected. But in the images where there is a big white space on top and bottom of the images, it gets cropped on the bottom in the png file. Like in the example below: Image where it is getting cropped

Here is the svg for the above png:

JavaScript

Now when I reduce the padding on the top and bottom by increasing the size of the drawing by manipulating the viewBox attribute, the image renders as expected, like shown below.

enter image description here

Below is the svg for the above png (this is working as expected):

JavaScript

I have compared the 2 svg files and viewBox is the only thing that is different. enter image description here

Any idea how can I resolve this?

Advertisement

Answer

Increasing the height of the filter area from 200% to 300% resolved the issue.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement