/    Sign up×
Community /Pin to ProfileBookmark

Constraining pictures uploaded sizes…

Hello,

I need a slight help with something I have planned to complete my web site project.

Currently I am allowing users to upload PNG, GIF and JPG to my site and only have a restriction on file size in Mb, being under 3Mb.

However, I have noticed when uploading wide and high pics that it makes the web page look pretty messy.

[B]Is there anything I can do to constrain the pictures width and height[/B]. In a perfect world, reduce them to fit on the page, then have a link to view it in a new window?

Any help would be greatly appreciated.

Mike.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyFeb 18.2006 — I currently use this script for images on my site[code=php]<?php
// Resize image.
// Writeen By: Smelban & Haker4o
// Mails [email protected] & [email protected]
// This code is written to only execute on jpg,gif,png

// $picname = resizepics('pics', 'new widthmax', 'new heightmax');
// Demo $picname = resizepics('stihche.jpg', '180', '140');


$picname = resizepics($_GET[fn],$_GET[w],$_GET[h]);
echo $picname;
//Funcion resizepics
function resizepics($pics,$newwidth,$newheight){
if(preg_match("/.jpg/i", "$pics")){
header('Content-type: image/jpeg');
}
if (preg_match("/.gif/i", "$pics")){
header('Content-type: image/gif');
}
list($width, $height) = getimagesize($pics);
if($width > $height && $newheight < $height){
$newheight = $height / ($width / $newwidth);
} else if ($width < $height && $newwidth < $width) {
$newwidth = $width / ($height / $newheight);

} else {
$newwidth = $width;
$newheight = $height;
}
if(preg_match("/.jpg/i", "$pics")){
$source = imagecreatefromjpeg($pics);
}
if(preg_match("/.jpeg/i", "$pics")){
$source = imagecreatefromjpeg($pics);
}
if(preg_match("/.jpeg/i", "$pics")){
$source = Imagecreatefromjpeg($pics);
}
if(preg_match("/.png/i", "$pics")){
$source = imagecreatefrompng($pics);
}
if(preg_match("/.gif/i", "$pics")){
$source = imagecreatefromgif($pics);
}
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
return imagejpeg($thumb);
if(preg_match("/.jpg/i", "$pics")){
return imagejpeg($thumb);
}
if(preg_match("/.jpeg/i", "$pics")){
return imagejpeg($thumb);
}
if(preg_match("/.jpeg/i", "$pics")){
return imagejpeg($thumb);
}
if(preg_match("/.png/i", "$pics")){
return imagepng($thumb);
}
if(preg_match("/.gif/i", "$pics")){
return imagegif($thumb);
}
}
?>
[/code]
and it is called like so (for a image called imagename.gif and for it to show as 500 x 500 px[code=php]<a href="thumb.php?fn=imagename.gif&amp;w=500&amp;h=500" target="_blank">[/code]f
×

Success!

Help @invision spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...