Re: [imagick] converting to variable instead of file
| From: | Decapode Azur | Date: | Sun, 07 Sep 2003 14:46:37 +0000 |
| Subject: | Re: [imagick] converting to variable instead of file | ||
| References: | 1 | Groups: | php.general php.general php.gtk.general php.gtk.general |
| Request: | Send a blank email to php-general+get-161908@lists.php.net to get a copy of this message | ||
finaly I did it this way : (pasted at the end of the mail)
But the problem is the result is very dirty,
considering the result with other way to do this.
http://grincheux.codelutin.org/~monnier/image.3.php.png
top-left is the image in XPM-format
top-right is the image in PNG-format
bottom-left is a classic php-gtk-script displaying an XPM image
bottom-right is the php-script below loading and displaying a PNG img
Why is the result so bad ?
=======================================
<?php
if ( !extension_loaded( 'gtk' ) )
strstr( PHP_OS, 'Linux' ) ? dl('php_gtk.so') :
dl('php_gtk.dll');
$handle = imagick_readimage( 'images/img.1.png' );
if ( imagick_iserror( $handle ) ) {
$reason = imagick_failedreason( $handle );
$description = imagick_faileddescription( $handle );
print "handle failed!\nReason: $reason\nDescription:
$description\n";
exit;
}
imagick_convert( $handle, 'XPM' );
if ( !( $image_data = imagick_image2blob( $handle ) ) ) {
$reason = imagick_failedreason( $handle );
$description = imagick_faileddescription( $handle );
print "imagick_image2blob() failed\nReason: $reason\nDescription:
$description\n";
exit;
}
$head = '!/\*\s*XPM\s*\*/\s*static\s*char\s*\*\[\]\s*=\s*{\s*/\*\s*columns
rows colors chars-per-pixel\s*\*/\s*!';
$image_data = preg_replace( $head, '', $image_data );
$image_data = preg_replace( '!/\*\s*pixels\s*\*/\s*!m', '', $image_data );
$image_data = preg_replace( '!"\s*};\s*$!', '', $image_data );
$image_data = preg_replace( '!(^"|",$)!m', '', $image_data );
$image_data = explode( "\n", $image_data );
$win = &new GtkWindow();
$win->connect( 'destroy', create_function( '', 'Gtk::main_quit();'
) );
$win->set_usize( 256, 256 );
$win->realize();
$transp = &new GdkColor( 1, 0, 0 );
list( $pixmap, $mask ) = Gdk::pixmap_create_from_xpm_d( $win->window,
$transp, $image_data );
$image = &new GtkPixmap( $pixmap, $mask );
$box = &new GtkVbox();
$box->add( $image );
$win->add( $box );
$win->show_all();
Gtk::main();
?>