PHP image processing class phpThumb parameter usage detailed explanation

WBOY
Release: 2016-07-25 08:53:23
Original
937 people have browsed it
  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/



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template