NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page 'Max Image Size'

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-09-2007, 09:39 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Dec 2004
Location: Florida
Posts: 2,617
Fewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud of
 


Save The Children

'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!
Fewski is offline  
Old 05-10-2007, 01:47 AM   #2 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
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.
Peter is offline  
Old 05-10-2007, 02:06 AM   #3 (permalink)
Senior Member
 
Camron's Avatar
Join Date: Jan 2006
Location: Portland, Oregon
Posts: 2,102
Camron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud ofCamron has much to be proud of
 



VA Tech Memorial 9/11/01 :: Never Forget Cancer Survivorship Child Abuse
Originally Posted by peter@flexiwebhost
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.
????: NamePros.com http://www.namepros.com/programming/326161-max-image-size.html

This is of course assuming you are using php as you have not actually stated the language in use.
I think he means something like vbulletin has, when you upload your avatar it must be smaller than X pixels by X pixels, if it's bigger, vbulletin won't upload it and it will let you know that it's too big.

I've never done something myself, but seeing it done in vbulletin there must be a way
__________________
HostingFuze.com Premium Master Reseller Services | 99.9% Uptime Guaranteed SLA | Starting at $4.95/mo
Basic Reseller Hosting @ HostFz.com - Services starting as low as $1.95/mo!
Camron is offline  
Old 05-10-2007, 04:46 AM   #4 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
Join Date: Oct 2005
Location: Portugal
Posts: 800
JFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to all
 



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];
}
hope this helps you
????: NamePros.com http://www.namepros.com/showthread.php?t=326161
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
Last edited by JFS; 05-10-2007 at 04:49 AM.
JFS is offline  
Old 05-10-2007, 09:00 AM THREAD STARTER               #5 (permalink)
Senior Member
Join Date: Dec 2004
Location: Florida
Posts: 2,617
Fewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud of
 


Save The Children
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!
Fewski is offline  
Old 05-10-2007, 10:29 AM   #6 (permalink)
New Member
Join Date: May 2007
Posts: 4
59codes is an unknown quantity at this point
 



Originally Posted by Fewski
Thanks for the posts all. Let me see if I can clear it up some:
????: NamePros.com http://www.namepros.com/showthread.php?t=326161

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!
That's Cropping
59codes is offline  
Old 05-10-2007, 01:55 PM   #7 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Originally Posted by 59codes
That's Cropping
No.. he's asking to scale the image down if it's over his max size, 400x400.
????: NamePros.com http://www.namepros.com/showthread.php?t=326161

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.
Dan is offline  
Old 05-10-2007, 02:13 PM THREAD STARTER               #8 (permalink)
Senior Member
Join Date: Dec 2004
Location: Florida
Posts: 2,617
Fewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud of
 


Save The Children
Originally Posted by Dan
No.. he's asking to scale the image down if it's over his max size, 400x400.
????: NamePros.com http://www.namepros.com/showthread.php?t=326161

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.
Hi Dan,

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.
Fewski is offline  
Old 05-10-2007, 02:23 PM   #9 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
Could you post the code? It only needs an if statement to check the size first.
Dan is offline  
Old 05-10-2007, 04:15 PM THREAD STARTER               #10 (permalink)
Senior Member
Join Date: Dec 2004
Location: Florida
Posts: 2,617
Fewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud ofFewski has much to be proud of
 


Save The Children
This should be it:

PHP Code:
//Create a new ad in the MySQL table, and upload the given image. $image is a reference to the image in $_FILES
    
function NewAd($owner_id$title$image$category$price$info$location)
????: NamePros.com http://www.namepros.com/showthread.php?t=326161
    {
        
$this->sql->query("SELECT * FROM ads WHERE title = '%s'"$title);
        
        
//Die if there's another ad with the same name
        
if($this->sql->num_rows() != 0)
        {
            echo 
"<script>alert('Sorry. Another ad exists with this title. Please choose another title.');</script>";
            return 
FALSE;
        }
        
//If $image is an array (i.e. not a link to an offsite hosted image)
        
if(is_array($image))
        {
            
$filext explode(".",$image['name']);
            
$filext $filext[(count($filext)-1)];
????: NamePros.com http://www.namepros.com/showthread.php?t=326161
            
            echo 
$image['name'] . '<br>';
            
            
move_uploaded_file($image['tmp_name'], AD_IMAGES.addslashes($title).'.'.$filext);
            
$image_url SERVER_ROOT.AD_IMAGES.addslashes($title).'.'.$filext;
        }
        elseif(empty(
$image))
            
$image_url 'http://www.racingrides.com/images/noimage.gif';
            
        
//If $image is the URL to an image hosted elsewhere.
        
else
            
$image_url $image;
        
//Query to add this information into the db
        
$this->sql->query("INSERT INTO ads SET owner = '%s', title = '%s', image = '%s', category = '%s', price = '%s', info = '%s', date = '%s', location = '%s'"$owner_id$title$image_url$category$price$infotime(), $location);
        
        return 
TRUE;
    } 
Thanks again Dan!
Fewski is offline  
Old 05-10-2007, 10:54 PM   #11 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue

Originally Posted by Fewski
I think the resizer is just the height="" width="" in the img code - not with the uploader code.
That's the problem right there. If you have an img tag like

PHP Code:
<img src="/path/to/image" width="400" height="400" /> 
All images will be sized to 400x400, small and large alike.

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:
<?php

// get the size of the image
list($width$height) = getimagesize(AD_IMAGES.addslashes($title).'.'.$filext);

// if width or height are greater than 400, scale down
if ($width 400 || $height 400)
????: NamePros.com http://www.namepros.com/showthread.php?t=326161
{
????: NamePros.com http://www.namepros.com/showthread.php?t=326161
    
// init the defaults
    
$x $y 400;

    
// scale the width and/or height
    
if ($width $height)
        
$y $height * (400 $width);
    else if (
$width $height)
        
$x  $width * (400 $height);

    
// now set the actual variables
    
$width intval(floor($x));
    
$height intval(floor($y));
}
?>

<!-- somewhere in your html -->
<img src="/path/to/image" width="<?=$width?>" height="<?=$height?>" />
Note that the above code does not actually scale the image file itself on disk; rather, it prints out the sized scale values in the img tag and lets the browser do the work.

If you actually want to scale the image file, it'll take a few extra lines of code.
cef is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:41 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger