473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

imagecopyresampled not working

Hello,

I'm trying to create thumbnails of PNG images. I have code that used to
work but doesn't seem to anymore. The resizing just seems to return black
images, even though my source image is not black. Anyone know what could be
the problem?

Here's my code:

$width = imagesx($im);
$height = imagesy($im);

if ($width >= $height) {
if ($width 32)
$thumbwidth = 32;
else $thumbwidth = $width;
$aspect = $width/$height;
$thumbheight = $thumbwidth/$aspect;
}
else {
if ($height 32)
$thumbheight = 32;
else $thumbheight = $height;
$aspect = $width/$height;
$thumbwidth = $thumbheight*$aspect;
}

$tim = ImageCreateTrueColor($thumbwidth,$thumbheight);

imagealphablending($tim, FALSE);
imagesavealpha($tim, TRUE);
$myBool = imagecopyresampled( $tim, $im, 0, 0, 0, 0, $thumbwidth,
$thumbheight, $width, $height);


Jun 13 '07 #1
3 5797
On Jun 13, 2:10 pm, "Bint" <b...@csgs.comwrote:
Hello,

I'm trying to create thumbnails of PNG images. I have code that used to
work but doesn't seem to anymore. The resizing just seems to return black
images, even though my source image is not black. Anyone know what could be
the problem?

Here's my code:

$width = imagesx($im);
$height = imagesy($im);

if ($width >= $height) {
if ($width 32)
$thumbwidth = 32;
else $thumbwidth = $width;
$aspect = $width/$height;
$thumbheight = $thumbwidth/$aspect;
}
else {
if ($height 32)
$thumbheight = 32;
else $thumbheight = $height;
$aspect = $width/$height;
$thumbwidth = $thumbheight*$aspect;
}

$tim = ImageCreateTrueColor($thumbwidth,$thumbheight);

imagealphablending($tim, FALSE);
imagesavealpha($tim, TRUE);
$myBool = imagecopyresampled( $tim, $im, 0, 0, 0, 0, $thumbwidth,
$thumbheight, $width, $height);
that works for me:
$im = "forest.png";

list($width, $height) = getimagesize($im);

if ($width >= $height) {
if ($width 32)
$thumbwidth = 32;
else $thumbwidth = $width;
$aspect = $width/$height;
$thumbheight = $thumbwidth/$aspect;
}else {
if ($height 32)
$thumbheight = 32;
else $thumbheight = $height;
$aspect = $width/$height;
$thumbwidth = $thumbheight*$aspect;
}

$tim = ImageCreateTrueColor($thumbwidth,$thumbheight);
$image = imagecreatefrompng($im);
imagealphablending($tim, FALSE);
imagesavealpha($tim, TRUE);
$myBool = imagecopyresampled($tim, $image, 0, 0, 0, 0, $thumbwidth,
$thumbheight, $width, $height);

header('Content-type: image/png');

imagepng($tim);

Jun 14 '07 #2
On Jun 13, 2:10 pm, "Bint" <b...@csgs.comwrote:
Hello,

I'm trying to create thumbnails of PNG images. I have code that used to
work but doesn't seem to anymore. The resizing just seems to return black
images, even though my source image is not black. Anyone know what could be
the problem?

Here's my code:

$width = imagesx($im);
$height = imagesy($im);

if ($width >= $height) {
if ($width 32)
$thumbwidth = 32;
else $thumbwidth = $width;
$aspect = $width/$height;
$thumbheight = $thumbwidth/$aspect;
}
else {
if ($height 32)
$thumbheight = 32;
else $thumbheight = $height;
$aspect = $width/$height;
$thumbwidth = $thumbheight*$aspect;
}

$tim = ImageCreateTrueColor($thumbwidth,$thumbheight);

imagealphablending($tim, FALSE);
imagesavealpha($tim, TRUE);
$myBool = imagecopyresampled( $tim, $im, 0, 0, 0, 0, $thumbwidth,
$thumbheight, $width, $height);
that works for me:

$im = "forest.png";

list($width, $height) = getimagesize($im);

if ($width >= $height) {
if ($width 32)
$thumbwidth = 32;
else $thumbwidth = $width;
$aspect = $width/$height;
$thumbheight = $thumbwidth/$aspect;
}else {
if ($height 32)
$thumbheight = 32;
else $thumbheight = $height;
$aspect = $width/$height;
$thumbwidth = $thumbheight*$aspect;
}

$tim = ImageCreateTrueColor($thumbwidth,$thumbheight);
$image = imagecreatefrompng($im);
imagealphablending($tim, FALSE);
imagesavealpha($tim, TRUE);
$myBool = imagecopyresampled($tim, $image, 0, 0, 0, 0, $thumbwidth,
$thumbheight, $width, $height);

header('Content-type: image/png');

imagepng($tim);

Jun 14 '07 #3
At Wed, 13 Jun 2007 12:10:16 -0500, Bint let h(is|er) monkeys type:
Hello,

I'm trying to create thumbnails of PNG images. I have code that used to
work but doesn't seem to anymore. The resizing just seems to return black
images, even though my source image is not black. Anyone know what could be
the problem?
At first glance your code seems fine. So the question probably boils down
to: is there a valid image in $im to begin with?

When running into the situation: it used to work but now it doesn't, ask
yourself what might have changed. New host, new PHP version, changed
php.ini, paths, permissions, changed includes etc.
Add some debugging steps along the way if you can't think of what has
changed, set error_reporting(E_ALL) to catch helpful notices and warnings.

--
Schraalhans Keukenmeester - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stijn Goris | last post by:
hi all, I 'm trying to resize an image if it is to big. After the user uploads (with move_uploaded_file()) an image, it is checked for its resolution. If the image is to big it will be resized...
1
by: bob4roxio | last post by:
Is there any better quality method for creating resized images? I'm using imagecreatetruecolor and imagecopyresampled and making sure my imagejpeg quality is set at 100 but the client I'm writing...
6
by: ralphNOSPAM | last post by:
When I execute this script, nothing displays on my browser. I'm trying to verify my image is being reduced by 50% before I try to write it to a file: // The file $filename =...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
1
by: lawrence k | last post by:
I'm looking at this page: http://us2.php.net/manual/en/function.imagecopyresampled.php I took the code from Example 2, almost exactly, and tried to use them on this page: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.