php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53640 XBM images require width to be multiple of 8
Submitted: 2011-01-03 04:30 UTC Modified: 2016-06-17 14:56 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 2ms67q83o001 at sneakemail dot com Assigned: cmb
Status: Closed Package: GD related
PHP Version: 5.6.11 OS: *
Private report: No CVE-ID:
 [2011-01-03 04:30 UTC] 2ms67q83o001 at sneakemail dot com
Description:
------------
makes file but text is not there, nor border

my nearly identical codes work perfect for imagejpeg(), imagegif() and
 imagepng()

why not imagexbm()????????????????

the imagewbmp() function has the same bug!!!

Test script:
---------------
<?php

header("Content-type: image/xbm");
$mytext = $_GET['mytext'];
$fontsize  = 5;
$wide  = imagefontwidth($fontsize) * strlen($mytext) + 20;
$high = imagefontheight($fontsize) + 20;
$picture = imagecreatetruecolor($wide,$high);
$gray = imagecolorallocate($picture,223,223,223);
$blue = imagecolorallocate($picture,0,0,255);
imagefill($picture,0,0,$gray);
$black=imagecolorallocate($picture, 0, 0, 0);
imageline($picture, 0, 0, 0, $high, $black);
imageline($picture, 0, 0, $wide, 0, $black);
imageline($picture, $wide-1, 0, $wide-1, $high-1, $black);
imageline($picture, 0, $high-1, $wide-1, $high-1, $black);
imagestring($picture,$fontsize,10,10,$mytext,$blue);
imagexbm($picture); //This function is only available if PHP is compiled with the bundled version of the GD library--is that the issue?
imagexbm($picture,mytextpic.xbm);
imagedestroy($picture);
rename("mytextpicxbm", "mytextpic.xbm"); //fixes bug in which image functions leave out dot

?>

Expected result:
----------------
bordered xbm image with text in it

Actual result:
--------------
makes file but text is not there, nor border either

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-04 02:40 UTC] 2ms67q83o001 at sneakemail dot com
-Summary: makes file but text is not there, nor border +Summary: makes file but text is not there, nor some of border -PHP Version: 5.2.16 +PHP Version: 5.2.11
 [2011-01-04 02:40 UTC] 2ms67q83o001 at sneakemail dot com
Description:
------------
makes file but text is not there, nor some of border

my nearly identical codes work perfect for imagejpeg(), imagegif() and
 imagepng() and image wbmp()

why not imagexbm()????????????????

Test script:
---------------
<?php

header("Content-type: image/xbm");
$mytext = $_GET['mytext'];
$fontsize  = 5;
$wide  = imagefontwidth($fontsize) * strlen($mytext) + 20;
$high = imagefontheight($fontsize) + 20;
$picture = imagecreatetruecolor($wide,$high);
$gray = imagecolorallocate($picture,223,223,223);
$blue = imagecolorallocate($picture,0,0,255);
imagefill($picture,0,0,$gray);
$black=imagecolorallocate($picture, 0, 0, 0);
imageline($picture, 0, 0, 0, $high, $black);
imageline($picture, 0, 0, $wide, 0, $black);
imageline($picture, $wide-1, 0, $wide-1, $high-1, $black);
imageline($picture, 0, $high-1, $wide-1, $high-1, $black);
imagestring($picture,$fontsize,10,10,$mytext,$blue);
imagexbm($picture); //This function is only available if PHP is compiled with the bundled version of the GD library--is that the issue?
imagexbm($picture,"mytextpic.xbm");
imagedestroy($picture);

?>

Expected result:
----------------
bordered xbm image with text in it

Actual result:
--------------
makes file but text is not there, nor some of border either
 [2011-01-04 04:30 UTC] 2ms67q83o001 at sneakemail dot com
I solved it! There are 2 huge errors on the page that describes the imagexbm() function and give examples. No one points out that the width MUST be evenly divisible by 8 or you get a mess. The example is 120 wide which just accidentally is evenly divisible by 8, which will happen only 1 in 8 times, randomly. This issue is dealt with in the code below. Also, since xbm is not color but black and white, the example should not be showing color anything, but it does. The code below is for black and white, and it works great. If there was a way, I'd erase the other stuff I wrote in this bug and put this comment here as a note on the imagexbm() page in PHP.NET!

<?php

header("Content-type: image/xbm");
$mytext = $_GET['mytext'];
$fontsize  = 5;
$wide  = imagefontwidth($fontsize) * strlen($mytext) + 20;
$temp1=$wide/8;
$temp2=round($wide/8);
if ($temp1<>$temp2){$wide=($temp2 * 8) + 8;}
$high = imagefontheight($fontsize) + 20;
$picture = imagecreatetruecolor($wide,$high);
$white = imagecolorallocate($picture,255,255,255);
imagefill($picture,0,0,$white);
$black=imagecolorallocate($picture, 0, 0, 0);
imageline($picture, 0, 0, 0, $high, $black);
imageline($picture, 0, 0, $wide, 0, $black);
imageline($picture, $wide-1, 0, $wide-1, $high-1, $black);
imageline($picture, 0, $high-1, $wide-1, $high-1, $black);
imagestring($picture,$fontsize,10,10,$mytext,$black);
imagexbm($picture); //This function is only available if PHP is compiled with the bundled version of the GD library
imagexbm($picture,"mytextpic.xbm");
imagedestroy($picture);

?>
 [2015-07-11 20:52 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=337142
Log: improved documentation of imagexbm according to #53640
 [2015-07-11 21:10 UTC] cmb@php.net
-Status: Open +Status: Assigned -Operating System: XP +Operating System: * -PHP Version: 5.2.11 +PHP Version: 5.6.11 -Assigned To: +Assigned To: cmb
 [2015-07-11 21:10 UTC] cmb@php.net
Indeed, XBM images can have only two colors, so everything other
than the given $foreground color is treated as background.

I have also documented the limitation that the image width has to
be a multiple of 8, but actually this limitation can easily be
fixed without causing a real BC break.

I have filed a respective ticked against libgd[1]. Let's see what
they say.

[1] <https://github.com/libgd/libgd/issues/170>
 [2015-07-11 21:11 UTC] cmb@php.net
-Summary: makes file but text is not there, nor some of border +Summary: XBM images require width to be multiple of 8
 [2015-07-23 16:50 UTC] cmb@php.net
-Status: Assigned +Status: Suspended
 [2016-06-17 14:56 UTC] cmb@php.net
-Status: Suspended +Status: Open
 [2016-06-17 14:56 UTC] cmb@php.net
Re-opening, because the issue has been fixed in libgd:
<https://github.com/libgd/libgd/commit/80ce084>.
 [2016-06-17 16:10 UTC] cmb@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ed0ec669968420ad0fa942c92d92b69a95e9beb1
Log: Fix #53640: XBM images require width to be multiple of 8
 [2016-06-17 16:10 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2016-06-17 16:24 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339384
Log: XBM images apply padding now (#53640)
 [2016-06-22 05:58 UTC] krakjoe@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ed0ec669968420ad0fa942c92d92b69a95e9beb1
Log: Fix #53640: XBM images require width to be multiple of 8
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Mon Apr 24 01:01:36 2017 UTC