Convert png to webp does not preserve transparency - imagemagick

Using the Google cwebp utility (https://developers.google.com/speed/webp/docs/cwebp) and the ImageMagick convert utility, I am unable to preserve transparency in png images when converted to webp.
Using convert I've tried using alpha-compression=0 and alpha-quality=100, without positive result. See: https://imagemagick.org/script/webp.php
The images I am working with have transparent corners for a rounded icon image.
Script being used (in Fish shell):
for file in *.png;
cwebp $file -o (basename $file .png).webp;
end;
and
for file in *.png;
convert $file (basename $file .png).webp;
end;

Never mind. It was my image editor which was not displaying the transparency properly. Transparency was still there. Now filing a bug report at https://github.com/linuxmint/pix/issues

Related

Drawing text on a gif while preserving transparency [FFMPEG]

Using the regular method, input > drawtext seems to remove transparency for GIFs and messes with the coloring
ffmpeg -i test.gif drawtext=text='Test':fontcolor=red:fontsize=24 output.gif
I've always tried using filter complex's palettegen and paletteuse, but those require arguments that drawtext doesn't provide:
ffmpeg -i banner.gif -filter_complex "[0:v] drawtext=text='Test':fontcolor=red:fontsize=24 [a]; [a] palettegen=reserve_transparent=1 [b]; paletteuse [a][b]" output.gif
What's the best way to efficiently draw text while preserving transparency?

Edit image files with Gimp script-fu

I'm trying to edit a pdf file with 100 pages, all of them images I need to export as png, setting their image mode as greyscale, and setting also their resolution, width and heigth.
How can I write a scheme (or python) script that perform this actions so that i could apply them by gimp in batch mode?
I've searched in the internet but didn't find simpy stated instructions.
ImageMagick's convert will do all this in one call in a command prompt:
convert -density 200 -colorspace Gray input.pdf -geometry 1000 ouput.png
will produce 1000px-wide grayscale PNGs (output-0 to output-(N-1).png) using a 200DPI rendering of the PDF.
You can also use Gimp scripting but you'll have a lot more to learn and AFAIK the API for the PDF loader only loads at 100DPI.
A slightly more manual method could be to:
Load (manually) the image in Gimp (you can specifiy the DPI in that case). This loads all the pages as layers.
Image>Mode>RGB to convert the image to grayscale.
Image>Scale image to set the size of all the pages
Save the individual layers to PNG (there are scripts for this, for instance this one)

Prevent ImageMagick from using indexed colors?

I have some PNG images with transparency. However, whenever I do any operations with ImageMagick on the image (e.g. cropping), it changes some of the images to be "indexed" color instead of RGB. The images that change are ones where there happens to be fewer than 256 colors, but the conversion ruins the transparency.
From some research I found you can prepend a filename with png32: to force RGB, but that only works when using the convert command, not mogrify.
I can add -format png32 with mogrify, but that renames all the images to *.png32.
Supposedly you can do this:
mogrify -define png:format=png32 -format png *.png
But it doesn't work, the images are still indexed color not RGB. How do I force PNG32 with mogrify?
Your command should have worked, if you are using a recent version of ImageMagick (6.9.1-3 or later).
Earlier versions will work if you use the -format png32 option as you did, then run a script to rename them back to *.png.
According to the ImageMagick 6 change log, the "-define png:format=png32" option was added to ImageMagick at version 6.7.3-0, but a bug was introduced at version 6.8.9-0 that caused it to be ignored in certain circumstances; that bug was fixed in version 6.9.1-3.
So the answer to your question is to either work around the problem by letting mogrify rename your input files to *.png32, or to upgrade your ImageMagick to 6.9.1-3 or later.

ImageMagick Command Line convert PNG to EPS with Transparency

I am trying to do a simple conversion from a transparent PNG file to EPS with transparency and currently my command looks like this:
convert "image1.png" "image1.eps"
It looks like all I am getting is a black image. Any ideas?
Thanks!
Converting a PNG to an EPS is more than just a simple format conversion. Its changing from a raster image to a vector image, so the raster image has to be "traced". The popular command line tool for doing this is potrace. With potrace installed (and its component tool mkbitmap) you could do it with something like this:
convert image1.png image1.bmp
mkbitmap image1.bmp -o image1.pgm
potrace image1.pgm -e -o image1.eps
The call to mkbitmap converts the color image to a graymap more suitable for tracing.
This will yield an eps with black lines on a white background. If you need a full color trace, inkskape is a GUI tool for doing this, and an inkscape user homebrewed a command line tool to do it, which can be found here

ImageMagick: Transparent Backgrounds for JPEG, not PNG

I'm using ImageMagick to convert PDF files to PNGs. (Lots of text, so I'd rather use PNG over JPEG.) I'm doing this on OS X, 10.8.2.
I tried using Ghostscript, then ImageMagick, as was done here and I got a gray background. I shortened it to one line, since ImageMagick can work with PDFs and tried this:
convert -background transparent -transparent white \
Background-Page01.pdf TestClearX1.png
I've tried that with PNG files and JPEG files. (And with and without -transparent white as well.)
If it's a JPEG, I can get a white background (which is probably clear, but in my viewer, I can't tell), but with a PNG, I always get a dark background. I thought about, as a test, trying to generate a BMP, then converting that to PNG, but it won't generate BMP files.
How can I get a transparent background for a PNG file?
And if that's not possible, since JPEG files are not good for text, is there a better alternative?
This isn't an answer, but the format of the comment section doesn't allow sensible formatting, so I am offering it here instead.
You alluded to the fact that Preview in OS X doesn't show transparency properly, and that is correct. To get around that, I made the following script, which overlays the files you want to view onto a checkerboard pattern like Photoshop does. I save it as preview and then use chmod +x preview on it to make it executable. Here is the script:
#!/bin/bash
################################################################################
# preview
# Preview images using OSX "open" but overlay images on top of checkerboard
# first so you can see transparency/transparent pixels, since Preview renders
# them grey :-(
################################################################################
for f in "$#"
do
base=$(basename "$f")
composite -compose Dst_Over -tile pattern:checkerboard "$f" "/tmp/$base"
open -g "/tmp/$base"
done
That enables you to do:
/.preview file1.png file2.gif
and the -g option also means Preview doesn't steal focus too :-)
So, instead of looking like this:
it looks like this:
There's two ways to export a PDF in LibreOffice, and one way does not provide any warnings. The other way provides a warning that PDF/A cannot have transparent objects. The problem is you're using PDF/A files that don't support transparent objects—this results in your PNG always having a background colour.

Resources