PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Nov 13, 2018 12:46 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Bitmaps in PHP
PostPosted: Thu Oct 18, 2007 12:50 am 
Offline
Forum Newbie

Joined: Wed Oct 17, 2007 1:48 am
Posts: 6
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 5:37 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 8:38 am 
Offline
Forum Newbie

Joined: Wed Oct 17, 2007 1:48 am
Posts: 6
scottayy | Please use
Syntax: [ Download ] [ Hide ]
,
[syntax=php]and
Syntax: [ Download ] [ Hide ]
  1. tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too. 
  2.  
  3.  
  4.  
  5.  
  6.  
  7. 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. 
  8.  
  9.  
  10.  
  11. Check out the following code.......the first should be a series of blue lines and second should be series of green lines. 
Syntax: [ Download ] [ Hide ]
<?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
Syntax: [ Download ] [ Hide ]
,
[syntax=php]and
Syntax: [ Download ] [ Hide ]
  1. tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: Posting Code in the Forums to learn how to do it too. 


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 9:09 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 19, 2007 9:30 am 
Offline
Forum Newbie

Joined: Wed Oct 17, 2007 1:48 am
Posts: 6
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 19, 2007 9:50 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 1:33 pm 
Offline
Forum Newbie

Joined: Wed Oct 17, 2007 1:48 am
Posts: 6
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group