morpe

resize img (jpg)

May 1st, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2. function mini($_F, $_DIR, $_W)
  3. {
  4.    
  5.     $load = $_F;
  6.     // percorso e nome file
  7.    
  8.     $name = explode(".", $load);
  9.     //separa nome dall'estensione
  10.    
  11.     //modifica l'immagine
  12.     $input_image = $load;
  13.     $size = getimagesize( $input_image );
  14.     $thumb_width = $_W;
  15.     $thumb_height = ( int )(( $thumb_width/$size[0] )*$size[1] );
  16.     $thumbnail = ImageCreateTrueColor( $thumb_width, $thumb_height );
  17.     $src_img = ImageCreateFromJPEG( $input_image );
  18.  
  19.     ImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1] );
  20.     ImageDestroy( $src_img );
  21.    
  22.     //salva l'immagine
  23.     ImageJPEG( $thumbnail, $_DIR.$name[0]."_thumb.jpg" );
  24.    
  25.     //libera la memoria
  26.     ImageDestroy( $thumbnail );
  27.    
  28. }
  29. //nome file con percorso - cartella di destinazione - largezza di destinazione
  30. mini("test.jpg","rsz/", 128);
  31.  
  32. ?>
Advertisement
Add Comment
Please, Sign In to add comment