Disadvantage: The long and wide picture will be stretched deformation, can not be intelligent cutting, the need for intelligent cutting, please do your own research.
$config = Array ();
$config [' path '] = "./";
$config [' t_width '] = 120;
$config [' t_height '] = 98;
$config [' ignore '] = Array ("", ".", "..");
$config [' prefix '] = "thumb_";
$done = 0;
Define ("Image_jpg", 2);
Define ("ENDL", "\ n");
if ($handle = Opendir ($config [' path ')]) {
while (false!== ($file = Readdir ($handle))) {
if (!array_search ($file, $config [' ignore '])) {
List ($im _width, $im _height, $type) = getimagesize ($file);
if ($type! = image_jpg) {
Continue
}
$op. = "Found-$file". ENDL;
$im = @imagecreatefromjpeg ($file);
if (! $im) {
$op. = "Fail-and couldn ' t create sour image pointer." ENDL;
Continue
}
if (file_exists ($config [' prefix ']. $file) | | substr ($file, 0, strlen ($config [' prefix '])) = = = $config [' prefix ']) {
$op. = "Note--and this file has already got a thumbnail." ENDL;
Continue
}
$to = Imagecreatetruecolor ($config [' t_width '], $config [' t_height ']);
if (! $to) {
$op. = "Fail-and couldn ' t create dest image pointer." ENDL;
Continue
}
if (!imagecopyresampled ($to, $im, 0, 0, 0, 0, $config [' T_width '], $config [' T_height '], $im _width, $im _height)) {
$op. = "Fail-and couldn ' t create thumbnail. PHP fail. ". ENDL;
Continue
}
Save File
Imagejpeg ($to, $config [' prefix ']. $file);
$op. = "Done-created thumb: {$config [' prefix ']}{$file}". ENDL;
$done + +;
}
}
}
Closedir ($handle);
$op. = "Fin-and {$done} file (s) written". ENDL;
echo "
";
Echo $op;
echo "
";
Exit
?>
The above describes the generation of thumbnails PHP batch generated thumbnails of the code, including the generation of thumbnails of the content, I hope the PHP tutorial interested in a friend helpful.