Page 1 of 1
Bitmaps in PHP
Posted: Thu Oct 18, 2007 12:50 am
by arjumand
Does PHP support only 256 colors...........I need to open bmps in the browser window through reading its entire structure but there is a color problem.Any help in this regard.Answer urgently needed.
Posted: Thu Oct 18, 2007 5:37 am
by onion2k
What PHP supports depends on which version of GD you're using. GD2 does true color (24 and 32 bit) stuff. However, PHP with GD2 doesn't support BMP images. There are a few functions around the internet that can open them as a GD resource though. If you're using one of these functions and the colours are wrong then I suspect it'll be an error in the function code rather than anything PHP or GD2 is doing.
Posted: Thu Oct 18, 2007 8:38 am
by arjumand
scottayy | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am using GD2 which comes with Easy-PHP 1.8.I am reading a bitmap pixel by pixel and displaying it on the browser window.For bitmaps that have 256 colors or less it is working fine but as soon as I reach the 257th color that 257th color is not displayed properly rather it is some approximaetd value.
Check out the following code.......the first should be a series of blue lines and second should be series of green lines.
Code: Select all
<?php
//draw1.php
Header("Content-type: image/jpeg");
$image = ImageCreate(500,400);
$gray = ImageColorAllocate($image,204,204,204);
for($i=0;$i<=255;$i++)
{
$blue = ImageColorAllocate($image,0,0,$i);
ImageLine($image,0,$i*2,150,$i*2,$blue);
}
for($j=0;$j<=255;$j++)
{
$green = ImageColorAllocate($image,$j,0,0);
ImageLine($image,175,$j*2,350,$j*2,$green);
}
ImageJPEG($image);
ImageDestroy($image);
?>
scottayy | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Oct 18, 2007 9:09 am
by onion2k
That's because you're using imagecreate() rather than imagecreatetruecolor(). You really ought to read the "Image" section of the PHP manual. There's a lot of stuff about creating images that's not very obvious when you're starting out.
You should also be aware than creating a 500 by 400 pixel image by reading every pixel from one image and drawing it on the other is going to be 200,000 reads, 200,000 colour allocations (maybe.. depends on your optimisation and source image), and 200,000 writes. That's not going to be very quick. You might also start hitting PHP's default memory limit.
Posted: Fri Oct 19, 2007 9:30 am
by arjumand
Ok thanks for the suggestion but please tell me then how to increase PHP's default memory limit as I have to read pixel by pixel data of bitmaps because its part of my project to understand image formats and get the details of their structure.I understand that this can be slow but it has to be done bcoz basically we are doing an image converter on the Web...........can u propose any optimized technique for me.
Posted: Fri Oct 19, 2007 9:50 am
by onion2k
There's lots of information about changing PHP's configuration on the PHP website. How you do it depends on your server really, and what you're allowed to modify.
As for proposing methods of optimising scanning and outputting an image ... I'm not going to suggest anything. For me to tell you how to do your project wouldn't help you learn anything. Think about it for a while. It's not rocket surgery.
Posted: Tue Oct 23, 2007 1:33 pm
by arjumand
Well I have been working on the project and now instead of doing pixel by pixel manipulation I read in a whole buffer and then display it but the drawing is still slow using the GD functions...........can this be overcome in any way.Please help me urgently as the deadline for project submission is quite near.................wud be really thankful.