Jump to content


Photo

Resizing Image Code


  • Please log in to reply
3 replies to this topic

#1 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 10 April 2006 - 04:03 PM

Is there a code which resize a picture if i is over a certain size. Like if maxium size was 100*100 and picture was 50*69 it would be left alone but if a picture was 50*105 it would be resized to 47*100 (its ratio).

Thank You

JJ

#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 10 April 2006 - 04:44 PM

Might look here...

[a href=\"http://fundisom.com/phpsnippets/snip/image_handling/resize_offsite_image/\" target=\"_blank\"]http://fundisom.com/phpsnippets/snip/image..._offsite_image/[/a]

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 11 April 2006 - 08:11 AM

The image url i want is in my database but the server wont let that code touch it (dunno why)?

Is there any other ways please?

#4 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 11 April 2006 - 08:41 AM

Ive found a code that works but it isnt exactly what i want :'(
(I get what i want ;) lol jk)

if(isset($_POST['Submit']))

{
     $size = 150; // the thumbnail height

     $filedir = 'pics/'; // the directory for the original image
     $thumbdir = 'pics/'; // the directory for the thumbnail image
     $prefix = 'small_'; // the prefix to be added to the original name

     $maxfile = '2000000';
     $mode = '0666';
     
     $userfile_name = $_FILES['image']['name'];
     $userfile_tmp = $_FILES['image']['tmp_name'];
     $userfile_size = $_FILES['image']['size'];
     $userfile_type = $_FILES['image']['type'];
     
     if (isset($_FILES['image']['name']))
     {
         $prod_img = $filedir.$userfile_name;

         $prod_img_thumb = $thumbdir.$prefix.$userfile_name;
         move_uploaded_file($userfile_tmp, $prod_img);
         chmod ($prod_img, octdec($mode));
         
         $sizes = getimagesize($prod_img);

         $aspect_ratio = $sizes[1]/$sizes[0];

         if ($sizes[1] <= $size)
         {
             $new_width = $sizes[0];
             $new_height = $sizes[1];
         }else{
             $new_height = $size;
             $new_width = abs($new_height/$aspect_ratio);
         }

         $destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
         $srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
         ImageCopyResized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg)) or die('Problem In resizing');
         ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
         imagedestroy($destimg);
     }



How could i make it so that the larger side (height or width) is the one that resizes.

example :
width 450 height 425
(width gets resized)
width 450 height 450
(both get resizing at exact same ratio)
width 425 height 450
(height resizes)


Please Help


Thank You




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users