生成缩略图
后端开发-php教程
缺点:长宽不一的图片会被拉伸变形,不能智能裁切,需要智能裁切的,请自行研究。<?php
$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 -> couldn’t create sour image pointer.” . ENDL;
continue;
}
if(file_exists($config[‘prefix’] . $file) || substr($file, 0, strlen($config[‘prefix’])) == $config[‘prefix’]) {
$op .= “note -> this file has already got a thumbnail.” . ENDL;
continue;
}
$to = imagecreatetruecolor($config[‘t_width’],$config[‘t_height’]);
if(!$to) {
$op .= “fail -> 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 -> couldn’t create thumbnail. php fail.” . ENDL;
continue;
}
//保存文件
imagejpeg($to, $config[‘prefix’] . $file);
$op .= “done -> created thumb: {$config[‘prefix’]}{$file}” . ENDL;
$done++;
}
}
}
closedir($handle);
$op .= “fin -> {$done} file(s) written” . ENDL;
echo “
smartquant 源码,ros调用vscode,ubuntu 346,tomcat 的lib,sqlite数据库题,php评论星星插件,前端框架大多面相单页面,有没有爬虫这个词语,count函数php,seo优化品牌推广,电商网站 magento,jcrop 截取网页,asp动态网页模板使用lzw
";
echo $op;
echo "
“;
exit;
?>
仿淘宝多用户商城系统源码,ubuntu系统硬件查看,tomcat6并发数调大,图书爬虫模拟登录,php刷脸支付系统看云,武汉seo方案lzw
以上就介绍了生成缩略图 PHP批量生成缩略图的代码,包括了生成缩略图方面的内容,希望对PHP教学有兴趣的朋友有所帮助。nz交易平台源码,vscode界面变方框,Ubuntu 关闭硬盘,tomcat的进程死锁,sqlite连接数据库路径,爬虫已在调试程序中暂停怎么回事,debian 8 php,宿州seo推广咨询热线,炫酷手机网站模板,模板元素lzw