| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Senior Member | 'Max Image Size' Is there a way to make a max image size? I have a site where people to upload photos.... I don't want the photos larger than 400x400 - but if someone uploads a phot thats a 100x100, I don't want it to be enlarged to 400x400 (Like what height="" width="" does). Is there a way to keep it where it resizes it if's it's larger than 400x400, but it doesn't if it's smaller? Thanks!
__________________ Twitter Friend Adder |
| |
| | #2 (permalink) |
| Senior Member | not 100% sure on what you mean. If you wish for the image to be displayed in it's actual size simply find the size and output that in the height="" width="" attributes using http://www.php.net/manual/en/function.getimagesize.php. This is of course assuming you are using php as you have not actually stated the language in use. |
| |
| | #3 (permalink) | |
| Senior Member | Quote:
I've never done something myself, but seeing it done in vbulletin there must be a way
__________________ || VPSByte Virtual & Dedicated Solutions || True 24/7/365 support with a 1 hour guaranteed response time! || We offer budget, yet powerful dedicated servers and vps solutions. || All servers come w/ 10Mbps unmetered bandwidth & lite management standard. | |
| |
| | #4 (permalink) |
| NamePros Regular | yes there is, i'm using this code, altough i write it a long time ago it does the work ( maybe i revised it someday ) Code: if ($_REQUEST[id]) {
//sets the max width in pixels
$maxwidth = "700";
// gets the image size - $get_dir = files"."/"; - in this case
$imagehw = GetImageSize($get_dir.$_REQUEST[id]);
// gets the size of the image in Kbs
$realsize = round(FileSize($get_dir.$_REQUEST[id])/1024);
// sets the real image width and height
$imagewidth = $imagehw[0];
$imageheight = $imagehw[1];
$realwidth = $imagewidth;
$realheight= $imageheight;
$imgorig = $imagewidth;
// resizes the image
if ($imagewidth > $maxwidth) {
$imageprop=($maxwidth*100)/$imagewidth;
$imagevsize= ($imageheight*$imageprop)/100 ;
$imagewidth=$maxwidth;
$imageheight=ceil($imagevsize);
}
// prints the result with some stuff...
$img .="<strong>This image is hosted for free.</strong></br>";
$img .="<a href='".$get_url.$_REQUEST[id]."' target='_blank'><img alt='' src='files/".$_REQUEST[id]."'border ='0' width='".$imagewidth."' height='".$imageheight."' /></a>";
$img .="</br>";
$img .="<strong>Image Resolution (".$realwidth."x".$realheight.") - Image size ".$realsize."Kbs</strong></br>";
$img .="- to save the image right click and 'Save as'</br>";
$img .="- to view the image in full size click on it</br>";
$subtitle="- viewing - ".$_REQUEST[id];
}
![]() you can see a live demo on http://imghosted.net/view.php?id=twc...-01301334b.jpg that way you get a ideia of what means what.
__________________ Joćo Fernandes Silva Selling : 19P.ORG - ARCADEHITS.ORG - AZIAN.NET - COREFANS.COM - CTUTORIALS.NET - DEDISEEK.COM - HITCHECK.COM - HOST15.COM - HOSTCUSTOMER.COM - LARGETIPS.COM - SCRIPTCANDY.COM - VISUALBOOK.NET - VOXVPS.COM / .NET - WALLPAPERSARENA.COM Last edited by JFS; 05-10-2007 at 03:49 AM. |
| |
| | #5 (permalink) |
| Senior Member | Thanks for the posts all. Let me see if I can clear it up some: 400x400 is max size If someone uploads a 800x800 image to my website, it will be resized to 400x400 automaticly. But if someone uploads a 300x350 image, the image will stay 300x350, there will be no resizing. Hope that clears it up some, and thanks for the posts!
__________________ Twitter Friend Adder |
| |
| | #6 (permalink) | |
| New Member | Quote:
| |
| |
| | #7 (permalink) | |
| Buy my domains. | Quote:
Fewski, do you already have the uploader and just need this resizing part? Resizing isn't hard to code, but it won't help if you don't have the uploader. | |
| |
| | #8 (permalink) | |
| Senior Member | Quote:
I have the uploader. I think the resizer is just the height="" width="" in the img code - not with the uploader code. It resizes the images fine that are over 400x400 - but it also does the images under 400x400 which I don't want. Thanks for the reply.
__________________ Twitter Friend Adder | |
| |
| | #10 (permalink) |
| Senior Member | This should be it: PHP Code:
__________________ Twitter Friend Adder |
| |
| | #11 (permalink) | |
| NamePros Regular | Quote:
PHP Code: In your PHP you need to determine the new scale size for the image (if it's too large), and then programmatically insert the height and width values into the <img> tag: PHP Code: If you actually want to scale the image file, it'll take a few extra lines of code. | |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |