Cropping a PNG file results in two blank files

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
Odexios
Posts: 4
Joined: 2014-12-13T10:48:35-07:00
Authentication code: 6789

Cropping a PNG file results in two blank files

Post by Odexios »

Hello everyone.

I'm trying to crop a series of PNG images; I scanned them on Ubuntu using Simple Scan. I've always used command-line IM to crop images in half, but this time, when using it like this:

Code: Select all

convert "$file_name.png" -crop '50x100%' +repage "$new_file_name.png"
on any of the images, all I get is two blank files (of the right resolution). Here's an example of an image with the results:
http://s5.postimg.org/4jpmuw553/026.png
http://s5.postimg.org/bx50tup6v/c026_0.png
http://s5.postimg.org/6a8nwdmo7/c026_1.png

Am I doing something wrong that with all the other files worked just because I was lucky? Is there something wrong with my scans? In the latter case, is there something I can do to crop them without having to redo them?

I've been looking around, but I didn't find anything useful; if it's a known problem and I wasn't able to search in a decent way, any pointer would be great.

EDIT: I was forgetting about it, here's my version id:

Code: Select all

Version: ImageMagick 6.7.7-10 2014-03-06 Q16
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropping a PNG file results in two blank files

Post by fmw42 »

Your 026.png got converted to a JPG by your hosting service. So it is hard to tell. But I suspect it may have a virtual canvas. As a JPG, it works fine for me on IM 6.9.0.0 Q16 Mac OSX using

Code: Select all

convert 026.jpg -crop 50x100% +repage tmp.png
Post to some other hosting service that does not convert to jpg. Or check identify -verbose 026.png and see if it has a virtual canvas (Page geometry: ... ) that has +X+Y that are not zero. If that is fine, then I suspect it is your old version of IM which is 120 versions old. You might want to upgrade.

You could also try removing the virtual canvas right after reading the input PNG

Code: Select all

convert 026.png +repage -crop 50x100% +repage tmp.png
Odexios
Posts: 4
Joined: 2014-12-13T10:48:35-07:00
Authentication code: 6789

Re: Cropping a PNG file results in two blank files

Post by Odexios »

I didn't expect a sneak conversion from postimg; apparently imgup behaved better:
http://k25.imgup.net/026fc30.png

The offset in the canvas has both X and Y equal to 0, and removing the virtual canvas before cropping still gave me the same results; I will try to compile the latest version as soon as I can, I hope it will fix the problem! Thank you for the suggestion!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropping a PNG file results in two blank files

Post by fmw42 »

Your png file works just fine for me on IM 6.9.0.0 Q16 Mac OSX Snow Leopard. Note that it could just be an issue of upgrading your libpng.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cropping a PNG file results in two blank files

Post by snibgo »

The PNG crops fine for me, v6.9.0-0 on Windows.
convert "$file_name.png" -crop '50x100%' +repage "$new_file_name.png"
This is obviously part of a larger script. You might double check that this is actually the file that is making white results: run your command against this single file.
snibgo's IM pages: im.snibgo.com
Odexios
Posts: 4
Joined: 2014-12-13T10:48:35-07:00
Authentication code: 6789

Re: Cropping a PNG file results in two blank files

Post by Odexios »

fmw42 wrote:Your png file works just fine for me on IM 6.9.0.0 Q16 Mac OSX Snow Leopard. Note that it could just be an issue of upgrading your libpng.
Thanks for the feedback, I was worried there was something wrong with the specific png files. I've been downloading a few other random png from the web, and I could crop them just fine, so I guess my version of IM has something specifically against this batch of scans. I'll see if an update resolves something, but it's good news anyway.
snibgo wrote:The PNG crops fine for me, v6.9.0-0 on Windows.
convert "$file_name.png" -crop '50x100%' +repage "$new_file_name.png"
This is obviously part of a larger script. You might double check that this is actually the file that is making white results: run your command against this single file.
Yeah, my fault for making it seem like part of a larger script. I'm writing a small script, but I wrote that line just for clarity. Apparently I missed my target xD Right now I'm actually writing

Code: Select all

convert 026.png +repage -crop '50x100%' +repage test.png
in a sandboxed folder with only one file. I just thought using pseudo-variables when posting would have been clearer, but it was just misleading.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropping a PNG file results in two blank files

Post by fmw42 »

Try with double quotes. What platform are you using?
Odexios
Posts: 4
Joined: 2014-12-13T10:48:35-07:00
Authentication code: 6789

Re: Cropping a PNG file results in two blank files

Post by Odexios »

Ubuntu 14.04 32 bit.

Just compiled the latest version, and it worked perfectly! Thanks to everyone for the help, you've saved my day!
Post Reply