Transparent Image Using GraphicsMagick - node.js

I am using GraphicsMagick and I am trying to create a 200px by 200px transparent TIF image. However, the resulting image, when opened in Photoshop, has a black background. If I use ImageMagick, it works.
The following ImageMagick command creates a transparent image (when opened in Photoshop)
magick convert -size 200x200 xc:transparent transparent1.tif
But, the same GraphicsMagic command creates a black image (when opened in Photoshop)
gm convert -size 200x200 xc:transparent transparent2.tif
I am at a loss. I would like to use GraphicsMagic because the Node API has streaming support and provides some other nice features.

Related

How to convert PNG/JPEG images to svg with ImageMagick?

It seems that with potrace installed, I can just run magick convert x.png x.svg or magick convert x.jpg x.svg.However this just returns a deformed image in black and white, and I need the svg image to be in full color. Additionally, I really need the file format to be svg because svg images are small and portable, and I don't have a lot of disk space on my server.Does anyone know how to convert png/jpeg to svg while retaining color?

Convert svg to png imagemagick black border around path

I am on macOs Mojave 10.14.3 (18D109)
My imagemagick details (installed with brew)
convert -version
Version: ImageMagick 7.0.8-35 Q16 x86_64 2019-03-25 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib freetype heic jng jp2 jpeg lcms ltdl lzma openexr png tiff webp xml zlib
I have a basic svg (adopted from W3Schools example):
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="52" height="52" viewBox="0 0 52 52">
<path fill="#fff" d="M22 0 L33 52 L12 42 Z">
</path>
</svg>
That looks like this (Gapplin):
Now when i convert it to png like so:
convert -background none -density 9600 -resize 32x "myFile.svg" "myFile.png"
i get a perfect image, except it has a black border:
I tried just about every variation of command options for imagemagick that had to do with color or black and sadly it never comes out with what i want - transparent background, solid white path (as described by fill on the SVG).
Any suggestions?
In ImageMagick, SVG files can be rendered by any one of three tools: Imagemagick's MSVG/XML, RSVG delegate and Inkscape, usually in order of increasing accuracy.
I just tried the following command with Inkscape 0.92.4 and it comes out totally white. If Inkscape is installed Imagemagick will use it automatically. But in this case it is not working well with that file.
magick test.svg test2.png
But it works fine if I added -background none
magick -background none test.svg test2.png
I get a white triangle on a transparent background.
or if I want a black background
magick -background black test.svg test2.png
When I force Imagemagick to use MSVG, I get a white triangle with a simple black outline on a white background. So again not correct by your comments.
magick MSVG:test.svg test2.png
If I add -background none, then I get white triangle with black outline on a transparent background.
magick -background none MSVG:test.svg test2.png
But if I just want a black background, then
magick -background black MSVG:test.svg test2.png
I then get a white triangle on a black background. But I suspect the white triangle is slightly smaller from the black border it had.
When I force the use of RSVG 2.44.12 by creating an entry in the delegates.xml file, I get a white triangle on a transparent background, which I assume is what you want.
magick RSVG:test.svg test3.png
or
magick -background none RSVG:test.svg test3.png
You can tell if your Imagemagick has MSVG/XML or RSVG by
magick -list format
and look for the line starting with SVG. At the end of that line it will either say XML or RSVG. You cannot tell about Inkscape with this method.
Check to see what you are using for your SVG renderer and its version. Also the version of libpng. Mine is 1.6.36
From your version information, I do not see rsvp listed. So I assume you are using MSVG, but it could be Inkscape if you have installed that on your system.
I am on Mac OSX Sierra with Imagemagick 7.0.8.35 Q16.
I had this problem converting SVG to PNG with PHP - black lines around the path. I install Inkscape on the server that was processing the image and that seemed to fix it, no code change necessary.
In my case, switching converters did not help.
Thus I experimented with the SVG itself.
And adding stroke-opacity="0" to the svg (or the individual paths if you dont want everything to have no outline) helped.
I assume that there is some default for stroke values that the converters set that makes them visible and this defines them as invisible on the svg level

Resize image to exact size by maintaining aspect ratio nodejs

I want to resize image to an exact size by maintaining aspect ratio and filling the empty space with transparency using nodejs.
I am able to do it using canvas. But due to some server os issues I can not use canvas.
I tried with imageMagick and gm. But couldn't find any option like these. Please show me a way to do this.
Thanks in advance.
In ImageMagick, you can resize and fill to the exact size by
convert image -resize WxH -background none -gravity center -extent WxH output
Input:
Here I will make the background black so you can see that if fills it out.
convert lena.jpg -resize 400x300 -background black -gravity center -extent 400x300 lena1.jpg
In case you have been successful using the canvas for resizing images, you can check out https://github.com/Automattic/node-canvas this repo.
As already mentioned you also resize images using ImageMagick by processes in NodeJS ( http://www.imagemagick.org/Usage/resize/ )
convert dragon.gif -resize 64x64 resize_dragon.gif
In case you have a lot of images, I would suggest that you write a terminal script ( NodeJS can achieve that as well ).
I hope it helps, in case you have more queries, feel free to ask.

ImageMagic renders image with black background

I'm converting pdf files to images with ImageMagic, everything is ok until I use -resize option, then I get image with black background. I use this command:
convert -density 400 image.pdf -resize 25% image.png
I need to use -resize option otherwise I get really large image. Is there any other option which I can use to resize image or is there option to set background in white.
That's not a Ghostscript command, You will need to find out what convert is sending to Ghostscript. As it stands I can't even be sure that your problem is with Ghostscript ,since it could easily be something that convert is doing.
Solved it by removing alpha from image, it seems imagemagic tries to apply some opacity but since jpeg doesn't allow transperency result was black background. So I found example on imagemagic website and it helped me:
convert a.pdf -background skyblue -alpha remove -alpha off a_remove.jpg

What command do you use to preview any image

I'm trying to write a command in sh using the software ImageMagick. I was trying to find a command that allows me use any image( presumably jpeg) and be able to preview the image but at a 200x200 pixels instead of the original size?
display -size 200x200 filename
See http://www.imagemagick.org/www/display.html
I use xv or xview:
xv -geom 200x200 filename
xview -geometry 200x200 filename

Resources