| 
	
 | 
 Posted by Shelly on 10/30/06 23:27 
<jason.tadeo@gmail.com> wrote in message  
news:1162246760.533931.252710@m7g2000cwm.googlegroups.com... 
>I was wondering if anyone does any uploading picture scripts or how to 
> do it where i could upload a picture and use php to change the picture 
> size to what i want it to be. Anyone know where i could learn how to do 
> this or have any script examples? i would really appreciate it alot. 
> 
> thanks for you time 
> 
> jason 
> 
 
I developed a little script that I used only for jpegs so far.  I haven't  
tested it with other image types.  Here it is: 
 
function thumbnail($img, $w_d, $h_d) { 
 // $img is the image 
 // $w_d is the desired width in pixels 
 // $h_d is the desired height in pixels 
 // 
 // function to get the width and height to display q thumbnail 
 // Pass in the image location, the deisred width and the desired height 
 // Ouput is an array of height and width to display that can be 
 // exploded with the list commant 
    list($w, $h, $type, $attr) = getimagesize($img); 
   $calc_width = $h_d * $w / $h; 
   $calc_height = $w_d * $h / $w; 
   if ($calc_width <= $w_d) { 
      $disp_width = $calc_width; 
      $disp_height = $h_d; 
   } else { 
      $disp_width = $w_d; 
      $disp_height = $calc_height; 
   } 
   return array($disp_width, $disp_height); 
} 
 
 
I call it with: 
 
list($disp_width, $disp_height) = thumbnail($the_picture_location, 500,  
500); 
 
and in the html area I have: 
 
<img src="the-picture-location" width="<?php echo $disp_height;?>"  
height="<?php echo $disp_height;?>" 
border="0" alt="something here" align="bottom" /> 
 
Hope that helps. 
 
Shelly
 
  
Navigation:
[Reply to this message] 
 |