Page 1 of 3

Unwanted gaps between combined PNG images

Posted: 2018-10-09T21:14:17-07:00
by xinmude
Hi, everyone:

I use a macOS High Sierra Version 10.13.4 and my ImageMagick is Version 6.9.0-0 Q16x86_64 2015-07-30.

I use the command "convert +append" and "convert -append" to combine two PNG images into one, and the exact command in an X-window is like

%convert +append im01.png im02.png final_im.png

but the resulting images have dark colored gaps between the two images. However, if I combine two JPG images into one using the same command, the resulting image does not have this kind of gap.

But I work with PNG images much more often. Could anyone tell how to avoid the dark colored gaps between images when you "convert +/-apend" PNG images into one?

Thank you,

R.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-09T23:01:48-07:00
by fmw42
Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-10T18:28:03-07:00
by xinmude
Thanks for reminding. I just added the version number of my ImageMagick and the exact command in the edited original post.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-10T18:29:41-07:00
by fmw42
The syntax should read the input images first, then +append, then the output.

Code: Select all

convert im01.png im02.png +append final_im.png
There should be no gaps between image. There could be a black or white border if the images are not the same size. You can control the color by using -background somecolor

Code: Select all

convert im01.png im02.png -background white +append final_im.png
Another issue might be that your PNG files have virtual-canvas offsets. You can remove that by adding +repage

Code: Select all

convert im01.png im02.png +repage +append final_im.png

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-10T20:19:54-07:00
by xinmude
Thank you for your reply!

I tried all your three suggestions, and the resultant image remains the same.

I'd like to let you know that I can see the dark gaps (as solid lines) between the two images in final_im.png when I view it in Preview, and the gaps show up as dashed lines in GraphicConverter.

And if I convert the final_im.png to final_im.jpg (convert final_im.png final_im.jpg), the gaps disappear in Preview.

Also, if I insert the final_im.png into a Word document, the dark gaps also disappear.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-10T22:52:19-07:00
by fmw42
Please post your im01.png im02.png to some free hosting service such as dropbox.com that won't change the format (or zip the files first). The post the URL(s) here.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-11T02:30:20-07:00
by xinmude
The images are as follows. As you can see, in the combined image there is a black line (the gap I am talking about) between the two images, and each image also has a borderline, and I suppose the gap is just the borderlines.

im01.png
Image

im02.png
Image

final_im.png
Image

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-11T02:39:45-07:00
by xinmude
I'm also posting the combined JPG image here. This is what I like: The images do not have borderlines, nor gap (or line) between them.

Image

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-11T04:18:16-07:00
by snibgo
I've never seen that added border, which also creates the line at at the gap. It might be a transient bug in IM.

As you are on a Mac, I guess you build IM yourself? If so, then I suggest you check the libraries, especially libpng. Perhaps an old library causes the problem.

Code: Select all

convert -list format |grep -i png
One entry on my computer is:

Code: Select all

      PNG* PNG       rw-   Portable Network Graphics (libpng 1.6.34)
           See http://www.libpng.org/ for details about the PNG format.
If your libpng is older, I suggest you upgrade it and rebuild IM.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-11T14:22:45-07:00
by xinmude
Thank you for your suggestion! I'll manage to upgrade it and let you know the result later.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-15T13:37:54-07:00
by xinmude
A colleague, who uses a Mac and ImageMagick Version 6.9.8 ..., tried the same thing on his machine with the two EPS files I sent him. The result is the same: There is a gap, or dark line, between the two images in the combined one.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-15T13:58:27-07:00
by snibgo
You still haven't provided the input files that you say are PNG format.

Your files in01.png etc are actually JPEG format.

For us to try to reproduce your problem, we need the exact command you used, and your exact input files.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-16T14:27:42-07:00
by xinmude
I have not used "montage" before---until now. After experimenting a little bit with "montage", I found that if I use "montage -geometry +0+0" instead of "convert +append" to combine two PNG images into one, those borderlines and the gap between the two images in the resulting PNG image are gone.

Now I am happy with this alternative method.

By the way, the images in my earlier posts were automatically changed to JPEG by the website (skydrive.live.com), not to my awareness initially.

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-17T16:04:04-07:00
by fmw42
There should not be any gaps with append. So that may be a bug in your version of Imagemagick or if on Linux, a bug in the distribution patch.

Your exact append command line would help us to help you.

Note that proper IM syntax would read the input images after convert and then apply the append and then write the output. Do not use the usual unix syntax of putting all the arguments before the input and output images. See https://imagemagick.org/Usage/basics/#why

Re: Unwanted gaps between combined PNG images

Posted: 2018-10-17T22:30:08-07:00
by xinmude
I tried both the following:

% convert +append im01.png im02.png final_im.png
% convert im01.png im02.png +append final_im.png

and got the same resulting image (with borderlines and gaps).

And this problem arises only when I work with PNG formatted files, not with JPEG files.

The problem with "montage", I just found, is that it leaves unnecessary spaces between images when it works with images with different width-height ratios.