$oimg = "Test.jpg";//original image Name
$classes = Array (' translation ', ' autoheight ', ' autowidth ', ' Stretch ');//give classes for the new creating images ' size Which is defined in the specified INI file
$suffix = ' jpg ';//the new image ' s suffix
$inifile = ' image.ini.php ';
$size = getimagesize ($oimg);
$x = $size [0]/$size [1];
$name = Explode ('. ', $oimg);
If (!file_exists ($inifile)) die (' INI file does not exist! ');
$CN = Parse_ini_file ($inifile, true);//parse the class style image size from INI file
foreach ($classes as $class) { foreach ($cn as $k = + $v) {
if ($k = = $class) {
if ($v [' width '] && $v [' height ']) {
$thumbwidth = $v [' Width '];
$thumbheight = $v [' height '];
}elseif ($v [' width ']) {
$thumbwidth = $v [' width '];
$thumbheight = round ($thumbwidth/$x);
} ElseIf ($v [' height ']) {
$thumbheight = $v [' height '];
$thumbwidth = Round ($thumbheight * $x);
} else{
$thumbwidth = $size [0];
$thumbheight = $size [1];
}
break;
}
}
if (!isset ($thumbheight) &&!isset ($thumbwidth)) die (' INI file Settings error! ');
$nimg = $name [0]. ' _ '. $class. '. $suffix;//new image file name
$source = Imagecreatefromjpeg ($oimg);
$thumb = Imagecreatetruecolor ($thumbwidth, $thumbheight);
Imagecopyresampled ($thumb, $source, 0,0,0,0, $thumbwidth, $thumbheight, $size [0], $size [1]);
if ($suffix = = ' jpg ') $method = ' imagejpeg ';
else $method = ' image '. $suffix;
$method ($thumb, $nimg);
Imagedestroy ($THUMB);//release the image source
Imagedestroy ($source);
}
?>
The PHP code that scales the picture, where the variable classes is an array, can select the settings specified in any number of INI files:
This is an INI configuration file, the above code will read this file in the image location, can be multiple.
; Translate the image format using the original image size
[Translation]
Width=0
Height=0
; Stretch the image to the specified size
[Stretch]
width=800
height=600
Zoom the image to the specified width with height auto size
[Autoheight]
width=740
Height=0
Zoom the image to the specified height with width auto size
[Autowidth]
Width=0
height=380
*/?>
Note: The INI file is interpreted as a comment file using PHP, and nothing is output, which is intended for security reasons. Instead, it is a comment for the INI file.
http://www.bkjia.com/PHPjc/632987.html www.bkjia.com true http://www.bkjia.com/PHPjc/632987.html techarticle php Tutorial $oimg = test.jpg;//original image name $classes = array (' translation ', ' autoheight ', ' autowidth ', ' Stretch '); /give classes for the new creating images ' size which is defi ...