<?
/*
# * usage:
# * resize.php [destination_width] [destination_height]
# *
# * destination_width and destination_height are optional
# * parameters for destination resize geometry
# *
# * resize.php will create output directory to save resized
# * images leaving originals intact
# *
# * This script uses "identify" and "convert" utilities which
# * are members of the ImageMagick suite of tools
# *
# */
# // input arguments for destination image size
$w2 = $argv[1]; // image width
$h2 = $argv[2]; // image height
#
# // both values should be numeric or use default size 800x600
if (!is_numeric($w2) || !is_numeric($h2)){
$w2 = 150; // default image width
$h2 = 190; // default image height
}
# // prepare directory name for saving resized images
# // directory name will look like "_800x600"
$dir = "Image";
#
# // create directory (inside current directory) for saving
# // resized images (@ means to be quiet - don't display
# // warning if directory alredy exists)
@mkdir($dir);
#
# // read files inside current directory
$files = scandir('.');
#
# // open loop for all fetched files in current directory
foreach ($files as $file){
# // convert file name to lower case
$file_lowercase = strtolower($file);
# // if file extension is jpg then process image
if (substr($file_lowercase, -3) == 'jpg'){
# // describe image format and image characteristics
$identify = shell_exec("identify $file");
# // read image geometry
preg_match('/(\d+)x(\d+)/', $identify, $matches);
$g1 = $matches[0]; // image geometry
$w1 = $matches[1]; // image width
$h1 = $matches[2]; // image height
# // prepare destination image geometry
if ($w1 < $h1) $g2 = $h2 .'x' .$w2;
else $g2 = $w2 .'x' .$h2;
# // print current image status
print "$file ($g1) -> $dir/$file_lowercase ($g2)\n";
# // resize image and save to destination directory
system("convert -size $g1 $file -resize $g2 $dir/$file_lowercase");
}
}
# ?>
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE