Page 1 of 1
Cropping hangs
Posted: 2016-08-16T12:26:33-07:00
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.
Re: Cropping hangs
Posted: 2016-08-16T12:30:59-07:00
by fmw42
What is your IM version and version of Windows?
Re: Cropping hangs
Posted: 2016-08-16T12:33:56-07:00
by nitu
ImageMagick-7.0.2-Q16 (Tried on ImageMagick-7.0.1-Q16) as well
Win 7 Ultimate SP1
Re: Cropping hangs
Posted: 2016-08-16T12:35:18-07:00
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.
Re: Cropping hangs
Posted: 2016-08-16T12:56:15-07:00
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.
Re: Cropping hangs
Posted: 2016-08-16T23:32:00-07:00
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.
Re: Cropping hangs
Posted: 2016-08-17T01:51:36-07:00
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.
Re: Cropping hangs
Posted: 2016-08-17T09:09:35-07:00
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?
Re: Cropping hangs
Posted: 2016-08-17T19:10:49-07:00
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
Re: Cropping hangs
Posted: 2016-08-18T02:46:23-07:00
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?