Forum Moderators: coopster

Message Too Old, No Replies

jpeg2bmp help please.

         

PhaZZed

9:43 am on Aug 13, 2007 (gmt 0)

10+ Year Member



This is my code:

-----------
$image = @imagecreatefromjpeg($filename);
if ($image === false) { die ('Unable to open image'); }

$height = imagesy($image);
$width = imagesx($image);

$bmpdest = "../bmp/" . $rand . ".bmp";
$bmp = jpeg2wbmp($filename, $bmpdest, 100, 100, 4);
-----------

It's creating the bmp image and everything, but once the .bmp is downloaded, when trying to open, it returns an error about an invalid image file..

Anyone able to shed some light?

Habtom

10:17 am on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$image = @imagecreatefromjpeg($filename);

Do you get any errors while the image is being converted? Try removing the "@" and check if that gives any errors.

Habtom

PhaZZed

11:05 am on Aug 13, 2007 (gmt 0)

10+ Year Member



No errors with or without the @..

That part is only used to fetch the height and width tho, so that I can use it for the height and width parameters for the conversion function..

[edited by: PhaZZed at 11:06 am (utc) on Aug. 13, 2007]

Scally_Ally

1:57 pm on Aug 13, 2007 (gmt 0)

10+ Year Member



so you only really need these lines,

$bmpdest = "../bmp/" . $rand . ".bmp";
$bmp = jpeg2wbmp($filename, $bmpdest, 100, 100, 4);

the only probs that it looks like it could be are
1. destination not writable
2. GD library not up to date
3. Set the filetype to .wbmp
($bmpdest = "../bmp/" . $rand . ".wbmp";)

whoisgregg

2:33 pm on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The jpeg2wbmp [php.net] function creates Wireless Bitmaps, not Windows Bitmaps.

PHP does not have native support for BMP files. The comments on the imagecreatefromwbmp [php.net] manual page may be helpful. :)

PhaZZed

2:41 pm on Aug 13, 2007 (gmt 0)

10+ Year Member



I ended up using phpThumb to do the conversion, just 'borrowed' their bmp class file:


require_once('phpthumb.functions.php');
require_once('phpthumb.bmp.php');
$filename = $_GET['file'];
$jpg = imagecreatefromjpeg($filename);
$phpbmp = new phpthumb_bmp();
$location = "../bmp/" . $rand . ".bmp";
file_put_contents($location, $phpbmp->GD2BMPstring($jpg));

Ye, WBMP creates a mono WAP style bmp file, not readable by Windows.

[edited by: PhaZZed at 2:43 pm (utc) on Aug. 13, 2007]