<? Php tutorial
$ Oimg = "test.jpg"; // original image name
$ Classes = array ('translation', 'autoheight', 'autowidth', 'Stretch '); // give classes for the new creating images 'size which are 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, $ 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 );
}
?>
Php code for Image Scaling. The variable classes is an array. You can select the settings specified in any number of INI files:
This is an ini configuration file. The above code will read the image location in this file, which can be multiple.
<? Php /*
; 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: When the INI file is interpreted as a php file, there is no output, which is intended for security reasons. The annotation of the INI file.