/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help Please: gd/php image resize is cropping not shrinking

I’m trying to create some thumbnails of images for a classifieds type page.

My host server is running:
PHP 4.3.2
GD support is:
GD support- enabled
GD version – bundled (2.0.12 compatible)
JPG support – enabled

My code seems to pretty much be working except it’s cropping the image to the thumbnail size rather than shrinking the image. I’m learning this function on the fly and I haven’t been able to track down a reason for this.

I’m hoping someone can spot why and help me out. 😮

If you need more info let me know

Here’s my call code:

[CODE]createThumbnail(“uploaded_files”, “$file”, “uploaded_files/thumbs”, 150);[/CODE]

Here’s the function:

[code]
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth)
{
$srcImg = imagecreatefromjpeg(“$imageDirectory/$imageName”);
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);

echo imagesx($srcImg);

$ratio = $thumbWidth / $origWidth;
$thumbHeight = $origHeight * $ratio;

$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbImg), imagesy($thumbImg));[/code]

Thanks in advance!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@annie_webbyauthorFeb 01.2008 — -facepalm-

duh. Ok. I fixed it. I was calling the wrong size here:

[CODE]imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbImg), imagesy($thumbImg));[/CODE]


This works:

[CODE]imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);[/CODE]
×

Success!

Help @annie_webby 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,
)...