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 » 2018-10-09T21:14:17-07:00

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: 25117
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 » 2018-10-09T23:01:48-07:00

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 » 2018-10-10T18:28:03-07:00

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: 25117
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 » 2018-10-10T18:29:41-07:00

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 » 2018-10-10T20:19:54-07:00

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: 25117
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 » 2018-10-10T22:52:19-07:00

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 » 2018-10-11T02:30:20-07:00

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 » 2018-10-11T02:39:45-07:00

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

Re: Unwanted gaps between combined PNG images

Post by snibgo » 2018-10-11T04:18:16-07:00

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 » 2018-10-11T14:22:45-07:00

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 » 2018-10-15T13:37:54-07:00

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

Re: Unwanted gaps between combined PNG images

Post by snibgo » 2018-10-15T13:58:27-07:00

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 » 2018-10-16T14:27:42-07:00

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: 25117
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 » 2018-10-17T16:04:04-07:00

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 » 2018-10-17T22:30:08-07:00

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