|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find image greater than x pixels?
Hi Guys, I have a little problem, was wondering if anyone had any experience with this? I am using imagemagick to remove whitespace from images, however some images are corrupt and the server hangs and eventually crashes because imagemagick doesnt know what to do, even though I have set the time out(doesnt seem to work). Currently I am using command line to find images in a directory and apply imagemagick command to them. Is there any way I can find images that are greater than 10x10 pixels for example? (All the corrupt images seem to be 0x0 pixels). I am currently using this command: Code:
find /directory/ -name "*.jpg" -exec mogrify -trim -fuzz 1% {} \;Any help would be much much appreciated. Thanks in advance! Mike |
| Sponsored Links | |
|
|
|
#2
|
|||
|
|||
|
Have you tried mogrify -verbose xxx.jpg ? For a legit image, it should return something like: Code:
$mogrify -verbose 1.jpg 1.jpg JPEG 100x171 100x171+0+0 8-bit DirectClass 8.99kb 1.jpg JPEG 100x171 100x171+0+0 8-bit DirectClass 8.95kb and for an image that is corrupt it should give an error message and return a non-zero exit code. I manually corrupted a file and it dealt with it, but that's not saying that I introduced anything similar to your situation. Mogrify is a part of the ImageMagick toolset, so it might have the same issues, but worth a try if you're not using it already. |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
Also identify(1) is part of imageMagick toolkit. It returns size of the image (3rd field), so you could easily do something like Code:
identify image.jpg | awk '{
print gensub(/x/," ","",$3)}' | #print space instead of 'x'
while read w h ; do #read in width and height
if [ $w = 0 ] || [ $h = 0 ] ; then
echo zero image
fi
done |
|
#4
|
|||
|
|||
|
Hi Agama,
Many thanks for the reply. I have just tried that on an image I know is corrupt and it does the same, just hangs and uses 100% of one of my cpu's. Had to kill the process. Doesnt throw an error or anything! I have the latest build so its all up to date. Any other ideas what I could possibly try? thanks for your help. mike ---------- Post updated at 06:41 PM ---------- Previous update was at 06:33 PM ---------- Quote:
Thanks for the response. That has confused me massively! ![]() So by looking at this it looks like it finds images that are 0x0 pixels and echos...? How can I incorprate my -trim syntax in to this and make it recursive on a directory? Sorry if I sound stupid! ![]() cheers, Mike |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
OK, let me be more specific. The code i posted above is a test for size of an image. You can save it in a script, that takes one argument -- image filename. Let's call it "trimNonzero.sh". The contents of this script would be: Code:
#!/bin/bash
# takes an image as argument and processes only if non-zero size
identify $1 | #get image info
awk '{print gensub(/x/," ","",$3)}' | #print size with space instead of 'x'
while read w h ; do #read in width and height
if [ $w = 0 ] || [ $h = 0 ] ; then
echo "$1 is zero image: width $w, height $h"
else
echo "processing image $1 ..."
mogrify -trim -fuzz 1% $1
fi
doneSave it, then make it executable: Code:
chmod u+x trimNonzero.sh Now you would process one image like: Code:
./trimNonzero.sh image.jpg Test it on one image. Now you can go ahead and run find to get all the files you want and execute the script instead of straight mogrify, like this: Code:
find $dir -name "*.jpg" -exec ./trimNonzero.sh {} \;Then come back and let us know how it went.
|
| Sponsored Links | ||
|
|
![]() |
| Tags |
| find image dimensions, find image pixels |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trying to find files equal to and greater than | bbbngowc | Shell Programming and Scripting | 4 | 07-06-2010 11:34 AM |
| find port greater than 6000 | gsiva | Shell Programming and Scripting | 1 | 09-03-2009 05:44 AM |
| find file size greater than 1 GB | ali560045 | Shell Programming and Scripting | 11 | 01-08-2009 09:16 AM |
| find lines have 2nd colum value greater than 40 | devesh123 | Shell Programming and Scripting | 5 | 10-01-2008 08:07 AM |
| Find lines greater than 80 characters in a file | mrgubbala | Shell Programming and Scripting | 8 | 03-10-2007 11:51 PM |
|
|