#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2

    Need help setting image size


    hey guys,

    whats the code used to set image size???

    this is what i got so far...

    Code:
    <?php
    
    				// You only need a single query to draw all the news section
    				// Remember that Limit number -currently 3- is just the news items you want to show in the main index
    
    				$data = mysql_query("SELECT id, day, month, year, headline, text, signature, img1, img2, img3 FROM news ORDER by ID DESC LIMIT 3", $CONNECT);
    				while($row = mysql_fetch_assoc($data))
    				{
    
    				echo '
    						<li>
    						<span>'.date('F ',$row['month']).' '.$row['day'].' ,'.$row['year'].'</span> <a href="#"><img src="images/racer2.jpg" alt=""></a>
    						<div>
    							<h3>'.$row['headline'].'</h3>
    							<p>
    								'.$row['text'].'
    							</p>
    							<a href="#">Read more &#62;&#62;</a>
    						</div>
    					</li>';
    				}
    					
    				?>
    many thanks
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,072
    Rep Power
    9398
    Do you know what size you want it to be? Or have the PHP in place to get the numbers if you don't?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    Nah all I want is the image to be the same size from one to the next all uniformed
  6. #4
  7. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,112
    Rep Power
    1990
    Image sizes are set by the 'height' and 'width' attributes.
    Code:
    <img src="image.jpg" width="200" height="150" alt="My Image" />
    You can set the sizes in your PHP script and output them into the HTML pretty easily.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    Originally Posted by Catacaustic
    Image sizes are set by the 'height' and 'width' attributes.
    Code:
    <img src="image.jpg" width="200" height="150" alt="My Image" />
    You can set the sizes in your PHP script and output them into the HTML pretty easily.
    Is that the same even tho im pulling them from a database table
  10. #6
  11. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,112
    Rep Power
    1990
    Yes. HTML doesn't know about your database and doesn't care. You just need to set the image size attributes and it will display the images at that size.

    Of course... if you haven't saved the images as that size, then they will be resized by the browser when they are displayed. You can create thumbnails using PHP if you need to, so if that's an issue you can go hunting around for some examples of that (there's a whole lot on here and other places so it's very easy to find).
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    Awesome I thoughtvi ised this code... but maybe not properly... ill see what I can figure out... lol thanks man...
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    52
    Rep Power
    2
    Cat I added the code for width and hight but still the images are not all uniformed..
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    88
    Rep Power
    77
    Here's a simple php function that returns the size in html tag format...it doesn't resize the picture itself, so I wouldn't recommend it for LARGE Pictures..... ***NOTE*** I didn't sanitize the php code..

    PHP Code:
    <?php
             
    // ..more php code above...this is just an php example
             
    $_FILES["photo"]["name"] = "photo_id.jpg";
             
    $mysock getimagesize($_FILES['photo']['tmp_name']);    
             
    $image_size imageResize($mysock[0], $mysock[1], 100);
             
    $page['image_name'] = $_FILES["photo"]["name"];
             
    $page['image_size'] = $image_size;
             
    $subject_id 1;

         function 
    imageResize($width$height$target) {
            
    //takes the larger size of the width and height and applies the
            //formula accordingly...this is so this script will work
            //dynamically with any size image
            
    if ($width $height) {
            
    $percentage = ($target $width);
            } else {
            
    $percentage = ($target $height);
            }
            
    //gets the new value and applies the percentage, then rounds the value
            
    $width round($width $percentage);
            
    $height round($height $percentage);
            
    //returns the new sizes in html image tag format...this is so you
            //can plug this function inside an image tag and just get the
            
    return "width=\"$width\" height=\"$height\"";
                    
    // returns the string in html format width="width_size" height="height_size"
         
    }

IMN logo majestic logo threadwatch logo seochat tools logo