 |
06-29-2007, 09:14 PM
|
#1 (permalink)
|
|
Contributing Member
Join Date: 06-20-07
Posts: 57
Latest Blog: None
|
How to resize images
Really stupid question, I know
How do you resize images in HTML?
Say I have <img src=url.png</img> and that image is 190x190 pixels but I want it 150x150 pixels. How do I do that. Thanks
|
|
|
06-29-2007, 10:43 PM
|
#2 (permalink)
|
|
Empress™
Join Date: 08-19-04
Location: York, UK
Posts: 18,417
|
<img src="url.png" width="150px">
or
<img src="url.png" style="width: 150px;">
I'd tend to use the latter. Though this will not resample your image and may leave your skewed image looking a little funny.
|
|
|
06-29-2007, 10:51 PM
|
#3 (permalink)
|
|
Inactive
Join Date: 06-29-07
Location: Indiana
Posts: 20
|
Your best bet is to resize it appropriately with a graphics program. If you do not have one, you can download free versions that will allow you to do this. Or you could download a demo/trial of one that isn't free and use it for just this purpose.
Free Solution: Gimp
Non-Free (but may have trial): Photoshop
|
|
|
06-29-2007, 11:22 PM
|
#4 (permalink)
|
|
Contributing Member
Join Date: 03-20-06
Posts: 115
|
If you don't use a graphics program to resize it, but instead use HTML then you're going to be wasting a lot of bandwidth and load time will be slower.
|
|
|
06-29-2007, 11:37 PM
|
#5 (permalink)
|
|
Contributing Member
Join Date: 05-30-06
Location: Canada
Posts: 466
Latest Blog: None
|
You used the code below OR give a search at phpclasses.org for OOP style or much more feature rich solution(s).
I found it in a book for PHP 1-2 years ago.
Code:
if (empty($max_width))
$max_width = 100;
if (empty($max_height))
$max_height = 80;
$image = "image.jpeg" // This is works only with JPEGs.
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = ImageCreateFromJpeg($image);
//$dst = ImageCreate($tn_width,$tn_height);
$dst = imagecreatetruecolor($tn_width,$tn_height);
//ImageCopyResized($dst, $src, 0, 0, 0, 0,
// $tn_width,$tn_height,$width,$height);
imagecopyresampled($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
header('Content-type: image/jpeg');
ImageJpeg($dst, null, 90);
ImageDestroy($src);
ImageDestroy($dst);
|
|
|
06-30-2007, 12:04 AM
|
#6 (permalink)
|
|
Contributing Member
Join Date: 06-20-07
Posts: 57
Latest Blog: None
|
Thanks for the help. The first is what I needed and only that will work. Hard to explain why, but thanks.
|
|
|
06-30-2007, 01:30 PM
|
#7 (permalink)
|
|
Inactive
Join Date: 04-21-06
Location: Boston
Posts: 28
Latest Blog: None
|
<img src=url.png</img> is not the correct way to format an image tag, the correct way is:
<img src="image.png" /> (no closing tag)
if you want it to validate as xhtml strict you also need to include an alt attribute: <img src="image.png" alt="Description of image" />
finally, you should never resize an image with html because it'll look terrible. resize with an image editor (jpmitchell has good suggestions above) and upload the new version.
|
|
|
07-02-2007, 12:06 PM
|
#8 (permalink)
|
|
Empress™
Join Date: 08-19-04
Location: York, UK
Posts: 18,417
|
Everyone is making things complicated. Just... straight and simple html above.
|
|
|
07-02-2007, 12:44 PM
|
#9 (permalink)
|
|
Contributing Member
Join Date: 05-30-06
Location: Canada
Posts: 466
Latest Blog: None
|
... if you display 100 images per page and the user clicks only on 5 images the server load will be huge.
|
|
|
07-02-2007, 03:44 PM
|
#10 (permalink)
|
|
Inactive
Join Date: 04-21-06
Location: Boston
Posts: 28
Latest Blog: None
|
Quote:
Originally Posted by chicgeek
Everyone is making things complicated. Just... straight and simple html above.
|
yes, straight and simple... of course, the straightest and simplest is to not resize an image with html or css. unless you want funny looking slow loading images 
|
|
|
07-02-2007, 04:29 PM
|
#11 (permalink)
|
|
Empress™
Join Date: 08-19-04
Location: York, UK
Posts: 18,417
|
Yes, but he didn't ask for an opinion on saving bandwidth or how to do it using a program. He asked how to do it in HTML. Not even PHP.
And as far as we know, it's one 300 x 300 image going down to 150 x 150. Not going to crash any servers any time soon.
|
|
|
07-02-2007, 09:33 PM
|
#12 (permalink)
|
|
Inactive
Join Date: 06-29-07
Location: Indiana
Posts: 20
|
@chicgeek - you are correct they didn't ask for all the options for saving it. However, there is no sense in taking a shortcut (even if one is available). One should be in the habit of doing things the proper way, as it will save them in the long run.
Just my 
|
|
|
07-07-2007, 01:53 PM
|
#13 (permalink)
|
|
v7n Mentor
Join Date: 03-14-06
Location: Montevallo Alabama
Posts: 1,227
|
Quote:
Originally Posted by jpmitchell
Your best bet is to resize it appropriately with a graphics program. If you do not have one, you can download free versions that will allow you to do this. Or you could download a demo/trial of one that isn't free and use it for just this purpose.
Free Solution: Gimp
Non-Free (but may have trial): Photoshop
|
Another free solution would be: Paint
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 07:38 AM.
© Copyright 2008 V7 Inc
|
|