Page 1 of 1

Cropping a PNG file results in two blank files

Posted: 2014-12-13T11:00:33-07:00
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

Re: Cropping a PNG file results in two blank files

Posted: 2014-12-13T11:23:00-07:00
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

Re: Cropping a PNG file results in two blank files

Posted: 2014-12-13T11:45:07-07:00
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!

Re: Cropping a PNG file results in two blank files

Posted: 2014-12-13T12:50:50-07:00
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.

Re: Cropping a PNG file results in two blank files

Posted: 2014-12-13T13:04:09-07:00
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.

Re: Cropping a PNG file results in two blank files

Posted: 2014-12-13T13:25:05-07:00
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.

Re: Cropping a PNG file results in two blank files

Posted: 2014-12-13T13:45:08-07:00
by fmw42
Try with double quotes. What platform are you using?

Re: Cropping a PNG file results in two blank files

Posted: 2014-12-13T14:33:44-07:00
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!