Scaled images come out completely transparent

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Geat
Posts: 3
Joined: 2019-03-02T14:08:12-07:00
Authentication code: 1152

Scaled images come out completely transparent

Post by Geat »

I'm trying to use ImageMagick's Lancsoz filter to create mip maps; initially it was erroring out because it said the CRC in the png i exported from GIMP is wrong (is there a way to make imagemagick ignore that?), so i changed to using an RGBA bitmap; so now i'm doing this:

Code: Select all

#!/bin/bash

diffuse0="./Base Color.bmp"
diffuse1="./Base Color-Mip1.png"
diffuse2="./Base Color-Mip2.png"

if [ ! -f "${diffuse0}" ] || [ "${diffuse0}" -nt "${diffuse1}" ]; then
	convert "${diffuse0}" -filter Lanczos -distort Resize 50%  "${diffuse1}"
fi

if [ ! -f "${diffuse2}" ] || [  "${diffuse1}" -nt "${diffuse2}" ]; then
	convert "${diffuse1}" -filter Lanczos -distort Resize 50% "${diffuse2}"
fi
And the files outputted are completely transparent. If i open the first one in GIMP and remove the alpha channel, i can see that the color data was all downsampled correctly, just that it has all 00s instead of all FFs in the alpha channel... While the second command just outputs an all black image, i assume its premultiplying the alpha.

What can i do about this? Am i missing some part of the command? I don't want to just discard the alpha channel because some images do use it for things...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scaled images come out completely transparent

Post by fmw42 »

What is your ImageMagick version, date and platform? Can you post an example input image to some free hosting service that won't modify your image (or zip it first). Then put the URL here so we can test your image.
Geat
Posts: 3
Joined: 2019-03-02T14:08:12-07:00
Authentication code: 1152

Re: Scaled images come out completely transparent

Post by Geat »

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic

$ convert --version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib

https://drive.google.com/open?id=12eSBT ... y4sNJR_l2k
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Scaled images come out completely transparent

Post by fmw42 »

This works fine for me on IM 6.9.10.29 Q16 Mac OSX with libpng 1.6.36

Code: Select all

convert "Base Color.bmp" -filter Lanczos -distort Resize 50%  result.png
Check your version of libpng and upgrade if old. Also your version of ImageMagick is over a year since it has been patched. See if there is a more current patch.

One issue with Linux distro versions of ImageMagick is they often patch only for security issues and not always for other bugs and enhancements. Also they do not update the version to match the date, so on the surface 6.9.7.4 is very old, but was patched Jan 2017. It is also possible that the version you have has a bug.

You can find your libpng version using

Code: Select all

convert -list format
look at the end of the line for PNG


Note that you can create all the levels at the same time. This writes each resized image to disk and uses that same image to resize for the next level.

Code: Select all

convert base.bmp \
-filter Lanczos -distort Resize 50% +write level0.png \
-filter Lanczos -distort Resize 50% +write level1.png \
-filter Lanczos -distort Resize 50% +write level2.png \
...
-filter Lanczos -distort Resize 50% +write levelN.png \
null:
This https://imagemagick.org/Usage/files/#write is an alternate approach resizing from the original.
Geat
Posts: 3
Joined: 2019-03-02T14:08:12-07:00
Authentication code: 1152

Re: Scaled images come out completely transparent

Post by Geat »

Well i can but i want to not create the files if they already exist, sort of like a make file.

I can't install the newer version; i get "/usr/bin/ld: /usr/local/lib/libfftw3.a(assert.o): relocation R_X86_64_PC32 against symbol `stdout@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC" And I can't remove libfftw3 to rebuild it because it so many things depend on it...

Thanks anyway though! Good to know that i'm using the tool correctly at least...
Post Reply