Source code for thumbnails in php

Source: Internet
Author: User
Thump. php :? Phpinclude_once (extra. php); $ pathassets; $ new_E: webrootblogtestassets \; define (END, n); define (TUD, $ dir); functionthumb ($ source, $ new_height) {list ($ im_width, $ im_height, $ type) getimage

Thump. php :? Php shortde_once ('extra. php '); $ path = 'Assets/'; $ new_height = 800; $ dir = 'e: \ webroot \ blog \ test \ assets \\'; define ("END", "\ n"); define ("TUD", $ dir); function thumb ($ source, $ new_height) {list ($ im_width, $ im_height, $ type) = getimage

Thump. php:

Include_once ('extra. php ');
$ Path = 'Assets /';
$ New_height = 800;
$ Dir = 'e: \ webroot \ blog \ test \ assets \\';
Define ("END", "\ n ");
Define ("TUD", $ dir );
Function thumb ($ source, $ new_height)
{
List ($ im_width, $ im_height, $ type) = getimagesize ($ source );
/* $ File = explode ('/', $ source );
$ File = array_pop ($ file );*/

$ File = basename ($ source );
Echo $ file;


If (! Is_writable ($ source )){
Trigger_error ('dir can \'t be write ');
// Touch ('thumb ');
}
$ New_width = $ im_width * $ new_height/$ im_height;
$ New_width = sprintf ('% d', round ($ new_width ));
Echo $ new_width;
$ Im = ImageCreatefromJpeg ($ source );
If (! $ Im)
Throw new Exception ('unable to read image file ');
$ Thumb = ImageCreateTrueColor ($ new_width, $ new_height );
ImageCopyResampled ($ thumb, $ im, 0, 0, 0, 0, $ new_width, $ new_height, $ im_width, $ im_height );
If (! Imagejpeg ($ thumb, 'thumb/'. $ file ))
Throw new Exception ('thumbnail failed ');
Imagedestroy ($ im );
Imagedestroy ($ thumb );
Unlink (TUD. $ file );
// Echo TUD. $ file. 'done ';
}
$ Data = enterDir (TUD );
// Print_r ($ data );
Foreach ($ data as $ v)
// Echo $ v;
Thumb (TUD. $ v, $ new_height );
/* $ Handle = opendir ('thumb /');
While (false! ==( $ File = readdir ($ handle ))){
$ Source = "thumb/". $ file;
Echo "$ file
";
}*/
?>
Extra. php:

Function enterDir ($ path)
{

If ($ handle = opendir ($ path )){
$ Data = array ();
While (false! ==( $ F = readdir ($ handle ))){
$ Ep = array ('.','..');
// $ Ext = substr ($ f,-3, 3 );
If (in_array ($ f, $ ep ))
Continue;
// If (filesize ($ path. $ f) <300)
// If (substr ($ f, 0, 3 )! = '000' | substr ($ f, 0, 3 )! = '000000 ')
// Continue;
$ Data [] = $ f;
}

/* $ Result = implode ("\ t \ n", $ data );
Echo $ result ;*/
Closedir ($ handle );


Return $ data;
}
}
$ Data = enterDir ('e: \ webroot \ blog \ test \ assets \\');
Print_r ($ data );
Foreach ($ data as $ k => $ v ){
$ Title = substr ($ v, 0,-4 );
$ Data [$ k] =' ';
// Echo $ v;
}
$ Data = implode ("\ r \ n", $ data );
Echo $ data;

/* Function ()
{

}
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.