Results 1 to 12 of 12

Thread: Resizing an Image

  1. #1
    Learning All I Can izwar's Avatar
    Join Date
    Feb 2006
    Location
    Miami
    Posts
    384

    Resizing an Image

    Hello,
    on my profile site where users have there profile picture, how do i make it a default size so even if the image is veyr big it will not distort the page, for example as of right now an image that is to big is doing this to the page

    http://www.hotclubber.com/memberinfo.php?id=36

    This is the coding around the image area including the table tag

    PHP Code:
    <td width="350" align="center"><?php
                
    if ($row['size']>0)
                {
                
    ?>
                              <img src="image1.php?id=<?php echo $row['urid'];?>" border="0" />
                              <?php
                
    }
                else
                { 
    ?>
                              <img src="images/comingsoon.gif" width="100" height="100" />
                              <?php
                
    ?></td>

    if someone can suggest something, i have my old developers telling me there gonna use java to solve this but htat doesnt really make sense. Anyone know any php code or something to solve this.

  2. #2
    Learning All I Can izwar's Avatar
    Join Date
    Feb 2006
    Location
    Miami
    Posts
    384
    just letting you know just by putting a size value in the img src filed with the PHP tag, i can make the images and size, but how do i make it so it resizes accordignly the image without distroting instead of putting every image to a size and distorting it.

  3. #3
    Sean
    Join Date
    Nov 2005
    Posts
    139
    Here is what I would do as far as steps:

    1. define a $maxwidth
    2. get the image's $oldwidth and $oldheight using the getimagesize() function
    3. open an if ($oldwidth > $maxwidth) condition
    4. have $newwidth = $maxwidth
    5. find the number ($scale) that $oldwidth would divide by to = $newwidth
    6. divide the $oldheight by $scale to get the scaled down height ($newheight)
    7. close the if, open an else
    8. have the $newwidth and $newheight = the $oldwidth and $oldheight
    9. close the else

    Sorry about not doing the actual coding, but I think it's good practice to do the actual coding yourself and just get help with the ideas behind the coding.

  4. #4
    Learning All I Can izwar's Avatar
    Join Date
    Feb 2006
    Location
    Miami
    Posts
    384
    that helps tremendoulsey thank you, and yes i will try this for practice my self, hopefully ill get it lol. If worst comes to worst i mite hav to ask you for the code lol. Ill do it in a few hours, thanks man appreciate it.

    P.S does the PHP url of the image go in the Getimagesize ( ) brackets?

    ima get to testing this out ill post my code when i get errors lol cuz i know ill get some.
    Last edited by izwar; 05-17-2006 at 06:44 PM.

  5. #5
    Sean
    Join Date
    Nov 2005
    Posts
    139
    Quote Originally Posted by izwar
    P.S does the PHP url of the image go in the Getimagesize ( ) brackets?
    Here's the php.net function page for getimagesize():

    http://us2.php.net/manual/en/function.getimagesize.php

    Basically, with this:

    "$size = getimagesize("http://www.example.com/gifs/logo.gif");"

    $size[0] will equal the width in pixels
    $size[1] will equal the height in pixels

    Hope that helps

  6. #6
    Learning All I Can izwar's Avatar
    Join Date
    Feb 2006
    Location
    Miami
    Posts
    384
    5. find the number ($scale) that $oldwidth would divide by to = $newwidth

    how would i find this since every image would be different.

    man im trying this out and its really hard dont know if ill get it.

  7. #7
    Learning All I Can izwar's Avatar
    Join Date
    Feb 2006
    Location
    Miami
    Posts
    384
    This is what i could try out, as i didnt understand the scale thing, but ive onyl really been doing php a few days so i think this mite be a lil to advanced. Can you just help me out with the code as i dont have time to get this working cuz its the last thing i need to launch my site. Thanks man Greatly greatly appreciated. I dont even know were to start the code you gave me, so its prlly in the wrong area.

    PHP Code:
    <td width="350" align="center"><?
                          $maxwidth 
    300;
                          
    $size getimagesize("image1.php?id=<?php echo $row['urid'];?>");
                          if (
    $oldwidth $maxwidth) {
                              
    $newwidth $maxwidth;
                            
    $scale 
                            
    $newheight $oldheight $scale;
                            }
                            else { (
    $newwidth $$ $newheight $oldwidth $$ $oldheight);
                            }

                          
                           
    ?>
                           <?php
                
    if ($row['size']>0)
                {
                
    ?>
                              <img src="image1.php?id=<?php echo $row['urid'];?>" border="0" />
                              <?php
                
    }
                else
                { 
    ?>
                              <img src="images/comingsoon.gif" width="100" height="100" />
                              <?php
                
    ?>

  8. #8
    Sean
    Join Date
    Nov 2005
    Posts
    139
    Ok, this might not be the best way to do it (just quickly coded) but it should work:

    Code:
      
    <?
    $imageurl = "http://www.domain.com/folder/image.gif";
    $maxwidth = 300;
    $size = getimagesize("$imageurl");
    $oldwidth = $size[0];
    $oldheight = $size[1];
    
    if ($oldwidth > $maxwidth) {
    $scale = $oldwidth / $maxwidth;
    $newwidth = $oldwidth / $scale;
    $newheight = $oldheight / $scale;
    }
    
    else { 
    $newwidth = $oldwidth;
    $newheight = $oldheight;
    } 
    
     ?>
    
    <img src="<? echo $imageurl; ?>" width="<? echo $newwidth; ?>" height="<? echo $newheight; ?>" >

  9. #9
    Learning All I Can izwar's Avatar
    Join Date
    Feb 2006
    Location
    Miami
    Posts
    384
    for $imageurl woudl i put this

    image1.php?id=<?php echo $row['urid'];?>

    as every image depends on their user id.

  10. #10
    Sean
    Join Date
    Nov 2005
    Posts
    139
    you wouldn't need the echo etc. because you're already in PHP, but yeah basically. Try:
    Code:
    $imageurl = "image1.php?id=$row['urid']";

  11. #11
    Registered
    Join Date
    Feb 2005
    Posts
    85
    better way is to resize the image and save it on the server with the new width/height (there is free php classes for image manipulaton), otherwise the user will download the whole image , but just resized virtually to the width/height in the <img> tag. You and the user will save traffic.

    for example:

    http://www.phpclasses.org/browse/package/1450.html
    http://www.phpclasses.org/browse/package/558.html
    http://www.phpclasses.org/browse/package/1980.html
    http://www.phpclasses.org/browse/package/871.html
    Last edited by ogito; 05-18-2006 at 05:22 AM.

  12. #12
    Learning All I Can izwar's Avatar
    Join Date
    Feb 2006
    Location
    Miami
    Posts
    384
    im still expirementing, but my old programmer is saying that hes gonna make a java script for the resizing and it will be better then using hte PHP way? any one agree with this or give me input.

Similar Threads

  1. Photoshop - How do I resize an image in a layer?
    By Erin in forum Graphics & Multimedia
    Replies: 8
    Last Post: 10-20-2014, 04:29 PM
  2. Replies: 6
    Last Post: 03-20-2011, 09:15 AM
  3. Google Image Search
    By cameron in forum Website Programming & Databases
    Replies: 6
    Last Post: 01-30-2008, 07:42 AM
  4. Image Borders for CSS
    By Chris in forum HTML, CSS, Layout, and Design
    Replies: 8
    Last Post: 08-11-2005, 09:41 AM
  5. Google Image Ads (Beta)
    By mobilebadboy in forum Advertising & Affiliate Programs
    Replies: 8
    Last Post: 06-17-2004, 11:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •