Unwanted gaps between combined PNG images

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?".
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Unwanted gaps between combined PNG images

Post 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.
Last edited by xinmude on 2018-10-10T18:25:30-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted gaps between combined PNG images

Post 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
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post by xinmude »

Thanks for reminding. I just added the version number of my ImageMagick and the exact command in the edited original post.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted gaps between combined PNG images

Post 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
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted gaps between combined PNG images

Post 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.
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post 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
Last edited by xinmude on 2018-10-16T10:08:59-07:00, edited 2 times in total.
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted gaps between combined PNG images

Post 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.
snibgo's IM pages: im.snibgo.com
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post by xinmude »

Thank you for your suggestion! I'll manage to upgrade it and let you know the result later.
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted gaps between combined PNG images

Post 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.
snibgo's IM pages: im.snibgo.com
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted gaps between combined PNG images

Post 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
xinmude
Posts: 15
Joined: 2018-10-09T20:38:36-07:00
Authentication code: 1152

Re: Unwanted gaps between combined PNG images

Post 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.
Post Reply