473,594 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is there BMP support in GD?

Hello,

I need to be able to read windows bitmap files (*.bmp) into the GD-functions
in order to create a jpg-file from it. Is such a thing possible. I seem te
be unable to find the required functions.

Hope you can help me.

Regards, Erwin
Jul 17 '05 #1
2 23431
All I can see in the php manual is support for .wbmp files.

Hamilton

"Erwin Bon" <er***@verkerk. nl> wrote in message
news:3f******** **************@ news.euronet.nl ...
Hello,

I need to be able to read windows bitmap files (*.bmp) into the GD-functions in order to create a jpg-file from it. Is such a thing possible. I seem te
be unable to find the required functions.

Hope you can help me.

Regards, Erwin

Jul 17 '05 #2
"Erwin Bon" <er***@verkerk. nl> wrote in message news:<3f******* *************** @news.euronet.n l>...
Hello,

I need to be able to read windows bitmap files (*.bmp) into the GD-functions
in order to create a jpg-file from it. Is such a thing possible. I seem te
be unable to find the required functions.

Hope you can help me.

Regards, Erwin


The GD library doesn't support .BMP files for some reason. I've
written a function that converts .BMP files to .GD, a very simple
format that GD uses.

The following code implements imagecreatefrom bmp(). It first convert
the BMP to GD, saving it to a temporary location, then open the image
using imagecreatefrom gd().
<?

function ConvertBMP2GD($ src, $dest = false) {
if(!($src_f = fopen($src, "rb"))) {
return false;
}
if(!($dest_f = fopen($dest, "wb"))) {
return false;
}
$header = unpack("vtype/Vsize/v2reserved/Voffset", fread($src_f,
14));
$info = unpack("Vsize/Vwidth/Vheight/vplanes/vbits/Vcompression/Vimagesize/Vxres/Vyres/Vncolor/Vimportant",
fread($src_f, 40));

extract($info);
extract($header );

if($type != 0x4D42) { // signature "BM"
return false;
}

$palette_size = $offset - 54;
$ncolor = $palette_size / 4;
$gd_header = "";
// true-color vs. palette
$gd_header .= ($palette_size == 0) ? "\xFF\xFE" : "\xFF\xFF";
$gd_header .= pack("n2", $width, $height);
$gd_header .= ($palette_size == 0) ? "\x01" : "\x00";
if($palette_siz e) {
$gd_header .= pack("n", $ncolor);
}
// no transparency
$gd_header .= "\xFF\xFF\xFF\x FF";

fwrite($dest_f, $gd_header);

if($palette_siz e) {
$palette = fread($src_f, $palette_size);
$gd_palette = "";
$j = 0;
while($j < $palette_size) {
$b = $palette{$j++};
$g = $palette{$j++};
$r = $palette{$j++};
$a = $palette{$j++};
$gd_palette .= "$r$g$b$a";
}
$gd_palette .= str_repeat("\x0 0\x00\x00\x00", 256 - $ncolor);
fwrite($dest_f, $gd_palette);
}

$scan_line_size = (($bits * $width) + 7) >> 3;
$scan_line_alig n = ($scan_line_siz e & 0x03) ? 4 - ($scan_line_siz e &
0x03) : 0;

for($i = 0, $l = $height - 1; $i < $height; $i++, $l--) {
// BMP stores scan lines starting from bottom
fseek($src_f, $offset + (($scan_line_si ze + $scan_line_alig n) *
$l));
$scan_line = fread($src_f, $scan_line_size );
if($bits == 24) {
$gd_scan_line = "";
$j = 0;
while($j < $scan_line_size ) {
$b = $scan_line{$j++ };
$g = $scan_line{$j++ };
$r = $scan_line{$j++ };
$gd_scan_line .= "\x00$r$g$b ";
}
}
else if($bits == 8) {
$gd_scan_line = $scan_line;
}
else if($bits == 4) {
$gd_scan_line = "";
$j = 0;
while($j < $scan_line_size ) {
$byte = ord($scan_line{ $j++});
$p1 = chr($byte >> 4);
$p2 = chr($byte & 0x0F);
$gd_scan_line .= "$p1$p2";
}
$gd_scan_line = substr($gd_scan _line, 0, $width);
}
else if($bits == 1) {
$gd_scan_line = "";
$j = 0;
while($j < $scan_line_size ) {
$byte = ord($scan_line{ $j++});
$p1 = chr((int) (($byte & 0x80) != 0));
$p2 = chr((int) (($byte & 0x40) != 0));
$p3 = chr((int) (($byte & 0x20) != 0));
$p4 = chr((int) (($byte & 0x10) != 0));
$p5 = chr((int) (($byte & 0x08) != 0));
$p6 = chr((int) (($byte & 0x04) != 0));
$p7 = chr((int) (($byte & 0x02) != 0));
$p8 = chr((int) (($byte & 0x01) != 0));
$gd_scan_line .= "$p1$p2$p3$p4$p 5$p6$p7$p8";
}
$gd_scan_line = substr($gd_scan _line, 0, $width);
}

fwrite($dest_f, $gd_scan_line);
}
fclose($src_f);
fclose($dest_f) ;
return true;
}

function imagecreatefrom bmp($filename) {
$tmp_name = tempnam("/tmp", "GD");
if(ConvertBMP2G D($filename, $tmp_name)) {
$img = imagecreatefrom gd($tmp_name);
unlink($tmp_nam e);
return $img;
}
return false;
}

$img = imagecreatefrom bmp("test24bit. bmp");
imagejpeg($img, "test.jpg") ;

?>
<img src="test.jpg">
Jul 17 '05 #3

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

Similar topics

4
9526
by: Aditya Ivaturi | last post by:
We have a CMS which is written is based on php & mysql. Recently we received a request to support multiple languages so that sites in that particular laguage can be created. I did some search on the google and it seems I have to build in multibyte support for php and mysql. Mbstring (http://us3.php.net/mbstring) claims to support multiple languages with a caution saying it might not work properly. After further research it seems unicode...
10
3151
by: Bill Davidson | last post by:
Hi there, Please forgive me for posting this article on multiple groups. Being new in the newsgroups, I was not sure which group would have been appropriate for my question. Sorry. My Question ----------- I am looking for a list of popular compilers and/or platforms that *do not* support native C++ exceptions. Any pointers in this
5
3483
by: shaun.mostashari | last post by:
Hello all, I am working on a trade study and one of the criterias is how easy it is to get DB2 technical support from IBM. I appreciate if you guys share your experience with me. Does DB2 have a good tech support?? Thanks in advance for any input. Shaun
5
3302
by: NormaJean Sebastian via DBMonster.com | last post by:
Hi, I almost read all of the "DB2 vs Oracle" thread... The summary I got from that was all databases essentially do the same things, the decision of which one you use primarily depends on available skillsets, software vendor support, and customer/tech support. I will be facing a decision on migrating our SAP Informix database to either Oracle, DB2UDB, or Sqlserver. I don't think we are going to SqlServer. I have some Oracle...
4
1545
by: Juan T. Llibre | last post by:
ASP.NET 1.0 Support Home http://support.microsoft.com/ph/6350 ASP.NET 1.1 Support Home http://support.microsoft.com/ph/6351 ..Net Framework 1.1 Support Site http://support.microsoft.com/ph/1249 ..Net Compact Framework Support Site
7
4301
by: Terry Olsen | last post by:
I paste the following code into each project to get XP theme support. 'Add this at the beginning of any program to enable Windows XP Visual Styles <System.STAThread()> Public Shared Sub Main() If OSFeature.Feature.IsPresent(OSFeature.Themes) Then System.Windows.Forms.Application.EnableVisualStyles() End If Application.DoEvents() 'This must be here, otherwise buttons won't stylize System.Windows.Forms.Application.Run(New Form1) End Sub...
1
3857
by: =?Utf-8?B?QW5kZXJ3IE1pbGxlcg==?= | last post by:
Apologies for posting in this forum, I don't see a more appropriate group... I'm trying to understand the timeline for Window 2003 ending mainstream support. I have consulted the MS lifecycle support center for 2K3 and 2K3 R2(http://support.microsoft.com/lifecycle/?p1=3198 and http://support.microsoft.com/lifecycle/?p1=10394 ) but it is unclear to me exactly when mainstream support ends. Both say 'Mainstream support will end two years...
1
2154
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a web server 32 bit and SQL server 2005 64bit . Does msdtc support SQL server 2005 64bit with web server 32 bit?
8
3152
by: Bill McCormick | last post by:
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> I assume "libraries" here to mean DLL's. If that's the case, is there any way to supply both ends of a service (client and host) with the code for the class that describes the contact WITHOUT a duplication in source code? Thanks.
0
7947
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7880
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8255
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.