Cropping hangs

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
nitu
Posts: 5
Joined: 2016-08-16T12:17:18-07:00
Authentication code: 1151

Cropping hangs

Post by nitu »

Hello.

I'm running the following code as a .bat file, to crop my images which range from 10000x10000 up to 20000x30000 px.

Code: Select all

for %%f in (*.jpg) do (
	convert %%f -crop 500x500 -set filename:tile "%%t_%%[fx:page.y/500+1]_%%[fx:page.x/500+1]" slices\%%[filename:tile].jpg
)
Simply put, the problem is that this script which previously worked brilliantly, now all of a sudden doesn't work ( on two different computers), but instead hangs the computer and slows it down to where it is barely usable.

I'm not sure whether it is related but the problems started after I tried to incorporate the above script in a .bat which creates the necessary subdirectories for all my image folders:

Code: Select all

setlocal

set "location=D:\Reg\B\N1"

for /d %%d in ("%location%\*") do (
  md "%%d\slices"
)

for %%f in (*.jpg) do (
	convert %%f -crop 500x500 -set filename:tile "%%t_%%[fx:page.y/500+1]_%%[fx:page.x/500+1]" slices\%%[filename:tile].jpg
)
It does create the folders but then it hangs.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropping hangs

Post by fmw42 »

What is your IM version and version of Windows?
nitu
Posts: 5
Joined: 2016-08-16T12:17:18-07:00
Authentication code: 1151

Re: Cropping hangs

Post by nitu »

ImageMagick-7.0.2-Q16 (Tried on ImageMagick-7.0.1-Q16) as well

Win 7 Ultimate SP1
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropping hangs

Post by fmw42 »

Did you install the legacy components so that you can use convert? Otherwise, you should replace convert with magick on IM 7. Sorry I do not use Windows, so cannot help further.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cropping hangs

Post by snibgo »

You have up to 600 M pixels. In Q16 v6, this will need 4.8 GB memory just to read the input file before cropping. (I'm not sure how much v7 uses.) As it "slows it down to where it is barely usable", I suspect you have run out of memory so it is using disk. How much RAM do you have? How much available RAM? Perhaps doing nothing else on the computer (eg running browsers) will solve the problem.

Using IM Q8 would half the memory usage.
snibgo's IM pages: im.snibgo.com
nitu
Posts: 5
Joined: 2016-08-16T12:17:18-07:00
Authentication code: 1151

Re: Cropping hangs

Post by nitu »

Just tried Q8, same thing. I have 16 GB on one computer and 8 GB on the other, both on which it worked great before. Indeed the memory usage seems to be maxed out, at least on one computer. It is still quite strange why a process that previously worked fine, would not work anymore.

I tried creating a new .bat file with just the conversion script, and it worked a few times, and a few times it didn't.
nitu
Posts: 5
Joined: 2016-08-16T12:17:18-07:00
Authentication code: 1151

Re: Cropping hangs

Post by nitu »

If someone has a better suggestion, I'm open to trying them. Basically I want a script that automatically detects any jpg:s in a directory, and crops & names them similar to what I have in my original script.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cropping hangs

Post by fmw42 »

What do you get from convert -version? Does it have HDRI on? Does it include JPG delegates? I do not know windows, but have you watched/checked your TMP directory (where ever that is) where IM holds temp copies to see that it is not getting full and has enough space allocated?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Cropping hangs

Post by snibgo »

nitu wrote:If someone has a better suggestion, I'm open to trying them.
If you often run out of memory, then buying more memory may be the obvious solution.

However, IM does have features to help this situation. For example, see http://www.imagemagick.org/Usage/files/#massive

You might try this:

1. Convert your large JPEG into a large MPC.
2. Make crops of that MPC. Each crop is the full width but only 500 pixels high.
3. From each crop, make your final crops.

Beware of the "Vanishing .cache files" bug, viewtopic.php?f=3&t=30256

The [suffix] mechanism might also help, eg

Code: Select all

convert large.jpg[20000x500+0+1500] row_3.miff
snibgo's IM pages: im.snibgo.com
nitu
Posts: 5
Joined: 2016-08-16T12:17:18-07:00
Authentication code: 1151

Re: Cropping hangs

Post by nitu »

I've found the reason behind the problem. The memory was indeed the issue, but mainly because I just used renamed .tif files (renamed .tif --> .jpg) to be able to run the script. I got the script from someone else with the instructions to use .jpg:s, hence the reason for renaming them. I did a batch conversion in irfanview and properly converted the .tif:s into .jpg:s instead of renaming them which resulted in the script running perfectly.

Although I must ask, shouldn't 16 GB RAM be enough to complete at least 1 image?
Post Reply