/    Sign up×
Community /Pin to ProfileBookmark

Proportional Image Resize

I’m trying to resize an image and here is a script I’m using.
However, the error I get is as follows:

[code=php]Warning: getimagesize(/v1dev/listingpicdir/17a8785ebe2665e197426ae6e9f80944/7tx.gif) [function.getimagesize]: failed to open stream: No such file or directory in ……etc.etc…[/code]

I can assure you that the above directory holds the image called 7tx.gif and that is not the issue…
however, the function getimagesize() fails to return anything…
and as a result the script below fails since it will not divide by ZERO.
here is the script

[code=php]//simple emaige resizing

function imageResize($width, $height, $target) {

//takes the larger size of the width and height and applies the
//formula accordingly…this is so this script will work
//dynamically with any size image

if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}

//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);

//returns the new sizes in html image tag format…

return “width=”$width” height=”$height””;

}

[/code]

Your help/advice is appreciated.
Thank you.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@tcaNov 26.2007 — getimagesize is telling you that the file does not exist probably because it can't follow the path you have given it. Adjust your path to the image and see if that works.

In which directory is the PHP file that contains getimagesize? That would help to resolve the path back to the image.

TC
Copy linkTweet thisAlerts:
@NogDogNov 27.2007 — Remember that getimagesize() is looking at a local filesystem path, not a web document path. On a UNIX/Linux system, "/" at the start of a pathname indicates the root directory of the current logical disk, so it is looking for a path starting with the directory "v1dev" which it expects to find immediately under the root "/" directory. Is this what you intended? Or, are really looking for it under your website's document root directory, e.g.:
[code=php]
getimagesize($_SERVER['DOCUMENT_ROOT'].'/v1dev/listingpicdir/17a8785ebe2665e197426ae6e9f80944/7tx.gif');
[/code]

?
Copy linkTweet thisAlerts:
@gomisuteauthorNov 27.2007 — Remember that getimagesize() is looking at a local filesystem path, not a web document path.
[code=php]
getimagesize($_SERVER['DOCUMENT_ROOT'].'/v1dev/listingpicdir/17a8785ebe2665e197426ae6e9f80944/7tx.gif');
[/code]

?[/QUOTE]


You are correct.

Thank you. I missed it somehow. The function now resizes with ease.
×

Success!

Help @gomisute 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...