Skip to content

Image dimensions and manipulation project.

Konstantinos Spalas edited this page Dec 23, 2018 · 3 revisions
#!/bin/bash
	 function dirLoop(){ 		
	 	 count=0	
		for filename in $1/*.jpg; do
			if [  -e $filename ];then							
		count=$(($count+1))
 		width=$(magick identify  -format  "%w"  $filename)
 		height=$(identify  -format  "%h"  $filename)
 		#echo filename $filename :
 		#echo the width is $width
 		#echo the height is $height 
 		if   [ $width -lt $2 ]; then 
 			echo  $filename : " width is $width px (reference is $referenceDimention)" >> /home/konnn/imageResults			
  			elif   [ $height -lt $2 ]; then 
 			echo  $filename :" height is $height px (reference is $referenceDimention)" >> /home/konnn/imageResults
 			fi
 	    else echo NO FILES IN $1 
 	    break
 	    fi
 	done
 	#return $count
	}

	directory=$1 #1st argmnt
	referenceDimention=$2 #2nd argmnt
		if   [ -z $directory  ]; then 
 			echo you forgot the 1st argument, exiting...
 			exit 0
 		fi 
  		if   [ -z $referenceDimention  ]; then 
 			echo you forgot the 2nd argument, exiting...
 			exit 0
  		fi
  	
  	#dirLoop $directory $referenceDimention
  	
  	cd $directory
  	array=$(find  $PWD  -maxdepth 2 -type d )
  	#echo -n ..search in inter direc $internalDir ...
  	#echo $array
  	for i in $array;do   
  		numOfFilesFound=0	
  		echo Searching in $i/  "for" images with $referenceDimention px dimension...
  			dirLoop $i $referenceDimention
  			echo ...scaned $count files. 	 	
  	
  	done
 	exit 0
 	

READ ME
This script runs from terminal and takes two arguments :
1. A directory path
2. A number, as reference, in order to compare the dimensions of images placed in directoty above

The results of images found with dimensions lower than reference are placed in a file create in home folder, named “imageResults”

Clone this wiki locally