Heim  >  Artikel  >  Backend-Entwicklung  >  PHP图片处理类 phpThumb参数用法详解

PHP图片处理类 phpThumb参数用法详解

WBOY
WBOYOriginal
2016-07-25 08:53:23903Durchsuche
  1. RewriteEngine on
  2. RewriteCond %{REQUEST_FILENAME} !-f
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteRule ^(.*)$ index.php?thumb=$1 [L,QSA]
复制代码

新建缩略图生成脚本:

新建 yoursite.com/thumbs/index.php

  1. $thumb = $_GET['thumb'];
  2. if (!$thumb) {
  3. exit;
  4. }
  5. //
  6. $thumb_array = explode('.',$thumb);
  7. $image = '../';
  8. foreach($thumb_array as $k=>$thumb_part){
  9. if ($k != count($thumb_array)-2) {
  10. $image .= $thumb_part . '.';
  11. }
  12. }
  13. $image = substr($image,0,-1);
  14. list($width,$height) = explode('x',$thumb_array[count($thumb_array)-2]);
  15. //
  16. if (file_exists($image)) {
  17. require('../phpthumb/phpthumb.class.php');
  18. $phpThumb = new phpThumb();
  19. $phpThumb->setSourceFilename($image);
  20. $phpThumb->setParameter('w',$width);
  21. $phpThumb->setParameter('h',$height);
  22. //$phpThumb->setParameter('far','C'); // scale outside
  23. //$phpThumb->setParameter('bg','FFFFFF'); // scale outside
  24. if ($phpThumb->GenerateThumbnail()) {
  25. mkdir(dirname($thumb),0777,true);
  26. if ($phpThumb->RenderToFile($thumb)) {
  27. header('Location: /thumbs/'.$thumb);
  28. exit;
  29. }
  30. }
  31. }
复制代码

测试缩略图生成: 上传一张图片到 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