Search code examples
graphicsmagick

GraphicsMagick: How to move image content from left side to center


Situation: I have a PNG image created from a SVG by exporting the image from Internet Explorer. Although the main motive in SVG is located in the center, in the exported PNG it appears in the left half. I used IE for the export because the quality of the PNG image is far better than results obtained by other tools.

Problem: I would like to use GraphicsMagick to shift the picture to the center. I could use crop to cut off the extra empty space on the right hand side, but I don't know how to add empty transparent space on the right.

SVG image:

PNG image:

What command should I use in Graphicsmagick to transform the PNG to a PNG with the logo located in the center while preserving the original square dimensions (500x500) of the image? (I was not satisfied with quality of PNG generated by GraphicsMagick from SVG directly)


Solution

  • This should do the trick:

    gm convert logo.svg -trim -gravity center -extent 500x500 result.png
    

    Setting the colour for the -extent makes it clearer what is happening:

    gm convert logo.svg -trim -gravity center -background pink -extent 500x500 result.png
    

    enter image description here