PHP image processing phpThumb parameter usage details
- RewriteEngine on
- RewriteCond % {REQUEST_FILENAME }! -F
- RewriteCond % {REQUEST_FILENAME }! -D
- RewriteRule ^ (. *) $ index. php? Thumb = $1 [L, QSA]
Script for creating a thumbnail:
Create 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. 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;
- }
- }
- }
Test thumbnail generation: upload an image to yoursite.com/images/myimage.jpg. open your browser and access yoursite.com/thumbs/images/myimage.10020.100.jpg to check the thumbs Directory. There should be a thumbnail, so you will not need to call PHP for. Official website http://phpthumb.gxdlabs.com/ |