[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-09-2007, 08:39 PM   #1 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Florida
Posts: 2,609
89.99 NP$ (Donate)

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!
__________________
Twitter Friend Adder
Fewski is offline  
Old 05-10-2007, 12:47 AM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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, 01:06 AM   #3 (permalink)
Senior Member
 
Camron's Avatar
 
Join Date: Jan 2006
Location: Portland, Oregon
Posts: 2,059
24.85 NP$ (Donate)

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
Quote:
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.

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
__________________
|| 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.
Camron is offline  
Old 05-10-2007, 03:46 AM   #4 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 760
56.85 NP$ (Donate)

JFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really nice


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
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.
JFS is offline  
Old 05-10-2007, 08:00 AM   #5 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Florida
Posts: 2,609
89.99 NP$ (Donate)

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!
__________________
Twitter Friend Adder
Fewski is offline  
Old 05-10-2007, 09:29 AM   #6 (permalink)
New Member
 
Join Date: May 2007
Posts: 4
0.00 NP$ (Donate)

59codes is an unknown quantity at this point


Quote:
Originally Posted by Fewski
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!
That's Cropping
59codes is offline  
Old 05-10-2007, 12:55 PM   #7 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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
Quote:
Originally Posted by 59codes
That's Cropping
No.. he's asking to scale the image down if it's over his max size, 400x400.

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, 01:13 PM   #8 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Florida
Posts: 2,609
89.99 NP$ (Donate)

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
Quote:
Originally Posted by Dan
No.. he's asking to scale the image down if it's over his max size, 400x400.

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.
__________________
Twitter Friend Adder
Fewski is offline  
Old 05-10-2007, 01:23 PM   #9 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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, 03:15 PM   #10 (permalink)
Senior Member
 
Join Date: Dec 2004
Location: Florida
Posts: 2,609
89.99 NP$ (Donate)

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)
    {
        
$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)];
            
            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, $info, time(), $location);
        
        return
TRUE;
    }
Thanks again Dan!
__________________
Twitter Friend Adder
Fewski is offline  
Old 05-10-2007, 09:54 PM   #11 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough

Animal Rescue
Lightbulb

Quote:
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)
{
    
// 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:03 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85