...

View Full Version : PHP imagecreate



cxn
08-28-2009, 04:15 PM
Hi, I'm looking to create a script which posts a random picture from an array.

Here's the coding:


<?php
header("Content-type: image/png");
$avatars[] = "sig/red.png";
$avatars[] = "sig/yellow.png";
$avatars[] = "sig/orange.png";
$avatars[] = "sig/green.png";
$avatars[] = "sig/blue.png";
$avatars[] = "sig/pink.png";

$avatar = $avatars[mt_rand(0, count($avatars)-1)];

$newavatar = imagecreatefrompng($avatar);
imagepng($newavatar);
imagedestroy($newavatar);

?>

When I try it in a browser it doesn't work though. It says the image contains errors.

Any help would be appreciated, thanks!

cxn
08-28-2009, 04:27 PM
Found a script that actually works, nevermind :-)

Fou-Lu
08-28-2009, 06:19 PM
If its like you're OP, you don't need imagecreate at all.
Given that you have the file already, you can pass the necessary header for it ('image/png' in this example), and use a file_get_contents or fread and pump it to the browser as an image.
GD library has a lot of overhead, if you already have an image and don't need to perform any manipulations to it, keep it simple by just serving it.

cxn
08-28-2009, 07:31 PM
Thank you, I didn't know that :-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum