Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc
Comunitatea PHP Romania
 

centered crop image
Vezi mesajul original

 
       Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc -> PHP Avansat
Subiectul anterior :: Subiectul următor  
Autor Mesaj
badtiger



Data înscrierii: 03/Noi/2006
Mesaje: 214

Trimis: Dum Mai 11, 2008 1:53 pm    Titlul subiectului: centered crop image  

Ma chinui sa fac un script care sa faca crop exact in mijlocul unei imagini
ceea ce am este:
Cod:
        $filename="test.jpg";
   $width = 80;
   $height = 80;
   $dimensions = getimagesize($filename);
   $canvas = imagecreatetruecolor($width,$height);
   $piece = imagecreatefromjpeg($filename);

   $newwidth = 80;
   $newheight = 80;
   $cropLeft = ($newwidth/ 2) - ($width/ 2);
   $cropHeight = ($newheight/ 2) - ($height/ 2);
   
   imagecopyresized($canvas, $piece, $cropLeft,$cropHeight, $newwidth, $newheight, $width, $height, $newwidth, $newheight);
   imagejpeg($canvas,$images_dir."/tb_".$filename,100);
   imagedestroy($canvas);
   imagedestroy($piece);

   if($size[0] > '300') {
   $Config_width_wide = 300;
   $Config_height_wide = 220;

   $Config_width_tall = 220;
   $Config_height_tall = 300;

   if($size[0] > $size[1]){
   $image_width = $Config_width_wide;
   $image_height = (int)($Config_width_wide * $size[1] / $size[0]);

   if($image_height > $Config_height_wide){
   $image_height = $Config_height_wide;
   $image_width = (int)($Config_height_wide * $size[0] / $size[1]);
   }
   }else{
   $image_width = (int)($Config_height_tall * $size[0] / $size[1]);
   $image_height = $Config_height_tall;

   if($image_width > $Config_width_tall){
   $image_width = $Config_width_tall;
   $image_height = (int)($Config_width_tall * $size[1] / $size[0]);
   }
   }
   $function_suffix = $gd_function_suffix[$filetype];
   $function_to_read = "ImageCreateFrom".$function_suffix;
   $function_to_write = "Image".$function_suffix;

   $source_handle = $function_to_read ($filename );

   if($source_handle){

   $destination_handle = ImageCreateTrueColor ( $image_width, $image_height );

   ImageCopyResampled( $destination_handle, $source_handle, 0, 0, 0, 0, $image_width, $image_height, $size[0], $size[1] );
   }
   $function_to_write( $destination_handle,$filename, 90 );
   ImageDestroy($destination_handle );
   }

   echo '<center><img src="'.$filename.'" border="1" /></center><br /><br />';


ms pt cei care ma vor ajuta
Sus  
agnus



Data înscrierii: 08/Iun/2006
Mesaje: 3

Trimis: Mar Mai 13, 2008 10:44 am    Titlul subiectului:  

Uite un exemplu. Face crop pe centrul imaginii dupa dimensiunile specificate in $thumb_width, $thumb_height.

Cod:

<?php
   
   header("Content-type:image/jpeg");
   
   $thumb_width = 50;
   $thumb_height = 50;
   
   $imagine_originala = imagecreatefromjpeg('poza.jpg');
   list($img_width,$img_height) = getimagesize('poza.jpg');
   
   $start_x = ( $img_width - $thumb_width ) / 2;
   $start_y = ( $img_height - $thumb_height ) / 2;
   
   $thumbnail = imagecreatetruecolor( $thumb_width , $thumb_height );
   
   imagecopy( $thumbnail , $imagine_originala , 0 , 0 , $start_x , $start_y , $img_width , $img_height );
   
   imagejpeg($thumbnail);
?>
Sus  
PHPRomania Bot
Bot Member


Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google
Trimis: Mie Dec 26, 2007 7:01 pm   Titlul subiectului: Ad  

Sus  
 
       Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc -> PHP Avansat
Pagina 1 din 1


Powered by phpBB 2.0.22 © 2001, 2002 phpBB Group
Varianta în limba română: Romanian phpBB online community