suchen
Heimphp教程php手册PHP图片处理类 phpThumb参数用法介绍
PHP图片处理类 phpThumb参数用法介绍Jun 13, 2016 pm 12:01 PM
php介绍mehrere参数图片基本处理haben用法Gebraucht

phpThumb几个基本参数
一些有用的参数列一下:
src:目标图片的地址
w:输出图片的宽度
h:输出图片的高度(如果不指定他将按w参数等比缩放)
q:输出如果是JPG格式的,可以规定它的输出质量
bg:输出时的背景(如果需要)
sw、sh、sx、sy:局部输出,宽高、起始位置
f:输出格式,可以为jpeg、png、gif、ico
sfn:输出gif动画中的某一帧
fltr[]:滤镜,可以有很多效果,包括锐化、模糊、旋翻转、水印、边框、遮照、色彩调整等
更多效果可以参看官方例程:
http://phpthumb.sourceforge.net/demo/demo/phpThumb.demo.demo.php
使用 phpThumb 和 .htaccess 来缓存缩略图
原理:用户访问 your.com/thumbs/images/image.50×50.jpg 这样的网址,脚本生成 your.com/images/image.jpg 的缩略图,并且保存到 your.com/thumbs/images/image.50×50.jpg,下次访问就不用调 PHP 啦。
简介
大约一年以前我碰到了 phpThumb 这个牛掰的脚本,它是个用来缩放图片的开源项目。当然你可以用 GD2 或者 imagemagick(magickwand) 来干同样的事情,但 phpThumb 是专门干这个的。它用起来相当简单:
PHP图片处理类 phpThumb参数用法介绍
如果访问量很大的话就撑不住了,因为 apache 要为每个图片的请求去调 PHP 来解析 phpThumb 的代码。尽管 phpThumb 自己有缓存,它还是要调 PHP 来决定是否从缓存里读。
我曾经看见有人用 mod_rewrite 把不存在的图片重定向到一个可以生成缩略图的脚本,以此来解决性能问题:
你需要:
Apache
mod_rewrite
PHP
这些东西通常虚拟主机都有,至于怎么安装就不在本文的讨论范围之内了。
OK,快告诉我怎么弄吧!
上传 phpThumb
从这里下载 phpThumb: http://phpthumb.sourceforge.net/ ,把它上传到 yoursite.com/phpthumb
配置 Mod_Rewrite
新建 yoursite.com/thumbs/.htaccess :

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?thumb=$1 [L,QSA]

新建缩略图生成脚本:
新建 yoursite.com/thumbs/index.php

复制代码 代码如下:


$thumb = $_GET['thumb'];
if (!$thumb) {
exit;
}
//
$thumb_array = explode('.',$thumb);
$image = '../';
foreach($thumb_array as $k=>$thumb_part){
if ($k != count($thumb_array)-2) {
$image .= $thumb_part . '.';
}
}
$image = substr($image,0,-1);
list($width,$height) = explode('x',$thumb_array[count($thumb_array)-2]);
//
if (file_exists($image)) {
require('../phpthumb/phpthumb.class.php');
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($image);
$phpThumb->setParameter('w',$width);
$phpThumb->setParameter('h',$height);
//$phpThumb->setParameter('far','C'); // scale outside
//$phpThumb->setParameter('bg','FFFFFF'); // scale outside
if ($phpThumb->GenerateThumbnail()) {
mkdir(dirname($thumb),0777,true);
if ($phpThumb->RenderToFile($thumb)) {
header('Location: /thumbs/'.$thumb);
exit;
}
}
}


测试一下!
上传一张图片到 yoursite.com/images/myimage.jpg
打开你的浏览器,访问 yoursite.com/thumbs/images/myimage.100×100.jpg
检查 thumbs 目录,应该有个缩略图在那。下次访问就不用调 PHP 啦。
官方网站 http://phpthumb.gxdlabs.com/
Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heiße Werkzeuge

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

SAP NetWeaver Server-Adapter für Eclipse

SAP NetWeaver Server-Adapter für Eclipse

Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

VSCode Windows 64-Bit-Download

VSCode Windows 64-Bit-Download

Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)