note 50400 added to function.imagecreatetruecolor
| From: | kuya1284 at techie dot com | Date: | Sun, 27 Feb 2005 07:48:12 +0000 |
| Subject: | note 50400 added to function.imagecreatetruecolor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85622@lists.php.net to get a copy of this message | ||
OverFlow636,
It appears that your code was causing TGA's to be inverted horizontally and upside down. I
modified your code accordingly. The sample below is an example of what I did to convert a tga to
jpg. The for loop was taken from the comment below (Eric Mulders) to properly render the image.
Nice job with the code buddy.
function tga2jpg ($image)
{
$handle = fopen($image, "rb");
$data = fread($handle, filesize($image));
fclose($handle);
$pointer = 18;
$w = fileint (substr ($data, 12, 2));
$h = fileint (substr ($data, 14, 2));
$x = 0;
$y = $h;
$img = imagecreatetruecolor($w, $h);
while ($pointer < strlen($data))
{
imagesetpixel ($img, $x, $y, fileint (substr ($data, $pointer, 3)));
$x++;
if ($x == $w)
{
$y--;
$x = 0;
}
$pointer += 3;
}
for($a = 0; $a < imagecolorstotal ($img); $a++)
{
$color = imagecolorsforindex ($img, $a);
$R=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 *
($color['blue']);
$G=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 *
($color['blue']);
$B=.299 * ($color['red'])+ .587 * ($color['green'])+ .114 *
($color['blue']);
imagecolorset ($img, $a, $R, $G, $B);
}
imagejpeg ($img, 'test.jpg', 100);
imagedestroy ($img);
}
function fileint($str)
{
return base_convert (bin2hex (strrev ($str)), 16, 10);
}
tga2jpg ('test.tga');
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatetruecolor.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50400
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50400&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50400&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50400&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50400&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50400&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50400&report=yes
Search -- http://master.php.net/manage/user-notes.php