Find image greater than x pixels?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find image greater than x pixels?
# 1  
Old 06-22-2011
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
# 2  
Old 06-22-2011
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.
# 3  
Old 06-22-2011
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  
Old 06-22-2011
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:
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

Hi Mirni,

Thanks for the response. That has confused me massively! Smilie

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! Smilie

cheers,

Mike
# 5  
Old 06-23-2011
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
    done

Save 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. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command size greater than or equalto

How do I find the files greater than or equal to a given size using find command. find ./ -size +0k --> Lists files greater than 0K find ./ -size 0k --> Lists the file size equal to 0K. I have other conditions to check, hence using find command. Thanks in advance. (4 Replies)
Discussion started by: deepakwins
4 Replies

2. Shell Programming and Scripting

Find and substitute if greater than.

I have large config-files for an application. The lines have different structure, but some of them contains the parameter 'TIMEOUT=x', where x is an numeric value. I want to change the value for that specific paramater if the value is greater than a specific value (got that?). The timeout-parameter... (3 Replies)
Discussion started by: useless
3 Replies

3. Shell Programming and Scripting

Help me to find a greater than or smaller than values

Hi, i need to find one of the value from my file is in between two numbers, that is the value is greater than 34 and smaller than 50, Ex: File.txt col1 col2 col3 col4 1 Name1 93 w 2 Name2 94 a 3 Name3 32 b 4 Name4 45 x 5 Name5 50 y 6 Name6 49 z here i need to find col3 values are... (7 Replies)
Discussion started by: Shenbaga.d
7 Replies

4. Shell Programming and Scripting

Find files greater than a particular date in filename.

I need a unix command which will find all the files greater that a particular date in the file name. say for example I have files like(filenaming cov : filename.YYDDMMSSSS.txt) abc.201206015423.txt abc.201207013456.txt abc.201202011234.txt abc.201201024321.txt efg.201202011234.txt... (11 Replies)
Discussion started by: lijjumathew
11 Replies

5. Shell Programming and Scripting

find greater than value

Hi I want to find greater than and min value. dategrep() { varlinenum=$1 varSESSTRANS_CL="$(egrep -n "<\/SESSTRANSFORMATIONINST>" tmpsess9580.txt | cut -d":" -f1)" echo $varSESSTRANS_CL } dategrep 8 Output of the above command is: I want to find out greater than 8 and... (9 Replies)
Discussion started by: tmalik79
9 Replies

6. Shell Programming and Scripting

Trying to find files equal to and greater than

Hi Guys and Gals, I'm having some difficulty putting this check into a shell script. I would like to search a particular directory for a number of files. The logic I have is pretty simple: Find file named *.txt that are newer than <this file> and count them If the number of files is equal to... (4 Replies)
Discussion started by: bbbngowc
4 Replies

7. Shell Programming and Scripting

find port greater than 6000

How to get the listening ports which is greater than 6000 using netstat ? (1 Reply)
Discussion started by: gsiva
1 Replies

8. Shell Programming and Scripting

Important finding --- find files greater than 1 MB

as we can find file greater than 1 MB with find command as: find /dir -name '*' -size +1M find /dir/* -name '*' -size +1M but wats its doing is , its finding files only in current directory not in sub-directories. i want files from sub-directories too. Please help... Thanx in... (3 Replies)
Discussion started by: manoj_dahiya22
3 Replies

9. Shell Programming and Scripting

find lines have 2nd colum value greater than 40

i have a file a.txt 12345,20 34567,10 23123,50 123456,45 how to find lines which hav 2nd entry greater than 40 o/p 23123,50 123456,45 pls help to get o/p (5 Replies)
Discussion started by: devesh123
5 Replies

10. Shell Programming and Scripting

Find lines greater than 80 characters in a file

Hi, Can anyone please give me the grep command to find all the lines in a file that exceed 80 columns Thanks, gubbala (8 Replies)
Discussion started by: mrgubbala
8 Replies
Login or Register to Ask a Question