Re: cvs: pear /PECL/imagick TODO imagick.c package.xml php_imagick.h /PECL/imagick/examples chop.php crop.php flip.php flop.php getimagedepth.php
getnumbercolors.php roll.php
| From: | Jon Wood | Date: | Thu, 05 Dec 2002 22:41:55 +0000 |
| Subject: | Re: cvs: pear /PECL/imagick TODO imagick.c package.xml php_imagick.h /PECL/imagick/examples chop.php crop.php flip.php flop.php getimagedepth.php getnumbercolors.php roll.php |
||
| References: | 1 | Groups: | php.pear.cvs |
| Request: | Send a blank email to pear-cvs+get-7749@lists.php.net to get a copy of this message | ||
Michael C. Montero wrote:
mcmontero Thu Dec 5 14:34:35 2002 EDTAdded files: /pear/PECL/imagick/examples chop.php crop.php flip.php flop.php getimagedepth.php getnumbercolors.php roll.php Modified files: /pear/PECL/imagick TODO imagick.c package.xml php_imagick.h Log:Added imagick_chop(), imagick_crop(), imagick_flip(), imagick_flop(), imagick_roll(), imagick_getimagedepth(), imagick_getnumbercolors(). ------------------------------------------------------------------------ Index: pear/PECL/imagick/TODO diff -u pear/PECL/imagick/TODO:1.2 pear/PECL/imagick/TODO:1.3 --- pear/PECL/imagick/TODO:1.2 Thu Dec 5 12:09:26 2002 +++ pear/PECL/imagick/TODO Thu Dec 5 14:34:34 2002 @@ -7,23 +7,15 @@ o imagick_append() => AppendImages() o imagick_average() => AverageImages() o imagick_clip() => ClipImage() -o imagick_getimagedepth() => GetImageDepth() o imagick_getimagetype() => GetImageType() o imagick_isimagesequal() => IsImagesEqual() o imagick_texture() => TextureImage() -o imagick_getnumbercolors() => GetNumberColors() o imagick_isgrayimage() => IsGrayImage() o imagick_ismonochromeimage() => IsMonochromeImage() o imagick_isopaqueimage() => IsOpaqueImage() o imagick_ispaletteimage() => IsPaletteImage() o imagick_querycolordatabase() => QueryColorDatabase() o imagick_querycolorname() => QueryColorName() -o imagick_thumbnail() => ThumbnailImage() -o imagick_chop() => ChopImage() -o imagick_crop() => CropImage() -o imagick_flip() => FlipImage() -o imagick_flop() => FlopImage() o imagick_mosaic() => MosaicImages() o imagick_profile() => ProfileImage() -o imagick_roll() => RollImage() o imagick_signature() => SignatureImage() Index: pear/PECL/imagick/imagick.c diff -u pear/PECL/imagick/imagick.c:1.13 pear/PECL/imagick/imagick.c:1.14 --- pear/PECL/imagick/imagick.c:1.13 Mon Dec 2 16:25:21 2002 +++ pear/PECL/imagick/imagick.c Thu Dec 5 14:34:34 2002 @@ -16,7 +16,7 @@| Christian Stocker (chregu@bitflux.ch) |+----------------------------------------------------------------------+ - $Id: imagick.c,v 1.13 2002/12/02 21:25:21 chregu Exp $ + $Id: imagick.c,v 1.14 2002/12/05 19:34:34 mcmontero Exp $ */ #ifdef HAVE_CONFIG_H @@ -71,6 +71,8 @@ PHP_FE( imagick_getwidth, NULL ) PHP_FE( imagick_getheight, NULL ) PHP_FE( imagick_getmimetype, NULL ) + PHP_FE( imagick_getimagedepth, NULL ) + PHP_FE( imagick_getnumbercolors, NULL ) /***** @@ -194,6 +196,18 @@ /***** + Transform an image. + + *****/ + + PHP_FE( imagick_chop, NULL ) + PHP_FE( imagick_crop, NULL ) + PHP_FE( imagick_flip, NULL ) + PHP_FE( imagick_flop, NULL ) + PHP_FE( imagick_roll, NULL ) + + /***** + Clean up. *****/ @@ -1002,6 +1016,87 @@ RETURN_STRINGL( mime_type, strlen( mime_type ), 1 ) ; } +PHP_FUNCTION( imagick_getimagedepth ) +{ + zval* handle_id ; /* the handle identifier coming from + the PHP environment */ + imagick_t* handle ; /* the actual imagick_t struct for the + handle */ + + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "r", + &handle_id ) == FAILURE ) + { + return ; + } + + handle = _php_imagick_get_handle_struct_from_list( &handle_id TSRMLS_CC ) ; + if ( !handle ) + { + php_error( E_WARNING, "%s(): handle is invalid", + get_active_function_name( TSRMLS_C ) ) ; + RETURN_FALSE ; + } + + _php_imagick_clear_errors( handle ) ; + + RETURN_LONG( GetImageDepth( handle->image, &handle->exception ) ) ; +} + +PHP_FUNCTION( imagick_getnumbercolors ) +{ + zval* handle_id ; /* the handle identifier coming from + the PHP environment */+ char* hist_file ; /* the path to the histogram file+ to write; note this can be + /dev/null */+ int hist_file_len ; /* string length of hist_file */+ imagick_t* handle ; /* the actual imagick_t struct for the + handle */+ FILE* fp ; /* file pointer to the histogram+ file */+ long unique_colors ; /* the number of unique colors */+ + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "rs", + &handle_id, &hist_file, &hist_file_len ) == FAILURE ) + { + return ; + } + + handle = _php_imagick_get_handle_struct_from_list( &handle_id TSRMLS_CC ) ; + if ( !handle ) + { + php_error( E_WARNING, "%s(): handle is invalid", + get_active_function_name( TSRMLS_C ) ) ; + RETURN_FALSE ; + } + + _php_imagick_clear_errors( handle ) ; + + if ( hist_file_len <= 0 ) + { + ThrowException( &handle->exception, ErrorException, "you must specify a histogram file; note the histogram file can be /dev/null", NULL ) ; + RETURN_FALSE ; + } + + fp = fopen( hist_file, "w" ) ; + if ( !fp ) + { + ThrowException( &handle->exception, FatalErrorException, "could not write to histogram file", NULL ) ; + RETURN_FALSE ; + } + + unique_colors = GetNumberColors( handle->image, fp, + &handle->exception ) ; + fclose( fp ) ; + + if ( _php_imagick_is_error( handle ) ) + { + RETURN_FALSE ; + } + + RETURN_LONG( unique_colors ) ; +} + /*****************************************************************************/ /****************************************************************************** @@ -3557,6 +3652,248 @@ new_handle->id = zend_list_insert( new_handle, le_handle ) ; RETURN_RESOURCE( new_handle->id ) ; +} + +/*****************************************************************************/ + +/****************************************************************************** + * + * Transform an image. + * + */ + +PHP_FUNCTION( imagick_chop ) +{+ zval* handle_id ; /* the handle identifier coming from+ the PHP environment */+ long coord_x ; /* x starting position of border */ + long coord_y ; /* y starting position of border */ + long width ; /* width of border */ + long height ; /* height of border */ + imagick_t* handle ; /* the actual imagick_t struct for the+ handle */ + RectangleInfo chop_info ; /* struct containing x, y, width and + height of border */+ Image* new_image ; /* the new image */+ + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "rllll", + &handle_id, &coord_x, &coord_y, &width, &height ) + == FAILURE ) + { + return ; + } + + handle = _php_imagick_get_handle_struct_from_list( &handle_id TSRMLS_CC ) ; + if ( !handle ) + { + php_error( E_WARNING, "%s(): handle is invalid", + get_active_function_name( TSRMLS_C ) ) ; + RETURN_FALSE ; + } + + _php_imagick_clear_errors( handle ) ; + + chop_info.width = width ; + chop_info.height = height ;+ chop_info.x = coord_x ; + chop_info.y = coord_y ;+ + new_image = ChopImage( handle->image, &chop_info, &handle->exception ) ; + if ( _php_imagick_is_error( handle ) ) + { + if ( new_image ) + { + DestroyImage( new_image ) ; + } + + RETURN_FALSE ; + } + + DestroyImage( handle->image ) ; + handle->image = new_image ; + + RETURN_TRUE ; +} + +PHP_FUNCTION( imagick_crop ) +{+ zval* handle_id ; /* the handle identifier coming from+ the PHP environment */+ long coord_x ; /* x starting position of border */ + long coord_y ; /* y starting position of border */ + long width ; /* width of border */ + long height ; /* height of border */ + imagick_t* handle ; /* the actual imagick_t struct for the+ handle */ + RectangleInfo geometry ; /* struct containing x, y, width and + height of border */+ Image* new_image ; /* the new image */+ + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "rllll", + &handle_id, &coord_x, &coord_y, &width, &height ) + == FAILURE ) + { + return ; + } + + handle = _php_imagick_get_handle_struct_from_list( &handle_id TSRMLS_CC ) ; + if ( !handle ) + { + php_error( E_WARNING, "%s(): handle is invalid", + get_active_function_name( TSRMLS_C ) ) ; + RETURN_FALSE ; + } + + _php_imagick_clear_errors( handle ) ; + + geometry.width = width ; + geometry.height = height ;+ geometry.x = coord_x ; + geometry.y = coord_y ;+ + new_image = CropImage( handle->image, &geometry, &handle->exception ) ; + if ( _php_imagick_is_error( handle ) ) + { + if ( new_image ) + { + DestroyImage( new_image ) ; + } + + RETURN_FALSE ; + } + + DestroyImage( handle->image ) ; + handle->image = new_image ; + + RETURN_TRUE ; +} + +PHP_FUNCTION( imagick_flip ) +{+ zval* handle_id ; /* the handle identifier coming from+ the PHP environment */+ imagick_t* handle ; /* the actual imagick_t struct for the+ handle */+ Image* new_image ; /* the new image */+ + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "r", + &handle_id ) == FAILURE ) + { + return ; + } + + handle = _php_imagick_get_handle_struct_from_list( &handle_id TSRMLS_CC ) ; + if ( !handle ) + { + php_error( E_WARNING, "%s(): handle is invalid", + get_active_function_name( TSRMLS_C ) ) ; + RETURN_FALSE ; + } + + _php_imagick_clear_errors( handle ) ; + + new_image = FlipImage( handle->image, &handle->exception ) ; + if ( _php_imagick_is_error( handle ) ) + { + if ( new_image ) + { + DestroyImage( new_image ) ; + } + + RETURN_FALSE ; + } + + DestroyImage( handle->image ) ; + handle->image = new_image ; + + RETURN_TRUE ; +} + +PHP_FUNCTION( imagick_flop ) +{+ zval* handle_id ; /* the handle identifier coming from+ the PHP environment */+ imagick_t* handle ; /* the actual imagick_t struct for the+ handle */+ Image* new_image ; /* the new image */+ + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "r", + &handle_id ) == FAILURE ) + { + return ; + } + + handle = _php_imagick_get_handle_struct_from_list( &handle_id TSRMLS_CC ) ; + if ( !handle ) + { + php_error( E_WARNING, "%s(): handle is invalid", + get_active_function_name( TSRMLS_C ) ) ; + RETURN_FALSE ; + } + + _php_imagick_clear_errors( handle ) ; + + new_image = FlopImage( handle->image, &handle->exception ) ; + if ( _php_imagick_is_error( handle ) ) + { + if ( new_image ) + { + DestroyImage( new_image ) ; + } + + RETURN_FALSE ; + } + + DestroyImage( handle->image ) ; + handle->image = new_image ; + + RETURN_TRUE ; +} + +PHP_FUNCTION( imagick_roll ) +{+ zval* handle_id ; /* the handle identifier coming from+ the PHP environment */+ long x_offset ; /* the number of cols to roll in the+ horizontal direction */+ long y_offset ; /* the number of rows to roll in the+ vertical direction */+ imagick_t* handle ; /* the actual imagick_t struct for the+ handle */+ Image* new_image ; /* the new image */+ + if ( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "rll", + &handle_id, &x_offset, &y_offset) == FAILURE ) + { + return ; + } + + handle = _php_imagick_get_handle_struct_from_list( &handle_id TSRMLS_CC ) ; + if ( !handle ) + { + php_error( E_WARNING, "%s(): handle is invalid", + get_active_function_name( TSRMLS_C ) ) ; + RETURN_FALSE ; + } + + _php_imagick_clear_errors( handle ) ; + + new_image = RollImage( handle->image, x_offset, y_offset,+ &handle->exception ) ;+ if ( _php_imagick_is_error( handle ) ) + { + if ( new_image ) + { + DestroyImage( new_image ) ; + } + + RETURN_FALSE ; + } + + DestroyImage( handle->image ) ; + handle->image = new_image ; + + RETURN_TRUE ; } /*****************************************************************************/ Index: pear/PECL/imagick/package.xml diff -u pear/PECL/imagick/package.xml:1.13 pear/PECL/imagick/package.xml:1.14 --- pear/PECL/imagick/package.xml:1.13 Tue Dec 3 11:28:20 2002 +++ pear/PECL/imagick/package.xml Thu Dec 5 14:34:34 2002 @@ -21,6 +21,20 @@</maintainer> <license>PHP License</license> <release> + <version>0.9.1.0</version> + <date>2002-12-05</date> + <notes>+ - functions added: + imagick_chop() + imagick_crop() + imagick_flip() + imagick_flop() + imagick_roll() + imagick_getimagedepth() + imagick_getnumbercolors() + </notes>+ </release> + <release> <version>0.9.0.1</version> <date>2002-12-03</date> <notes>Index: pear/PECL/imagick/php_imagick.h diff -u pear/PECL/imagick/php_imagick.h:1.7 pear/PECL/imagick/php_imagick.h:1.8 --- pear/PECL/imagick/php_imagick.h:1.7 Mon Dec 2 16:25:21 2002 +++ pear/PECL/imagick/php_imagick.h Thu Dec 5 14:34:34 2002 @@ -16,7 +16,7 @@| Christian Stocker (chregu@bitflux.ch) |+----------------------------------------------------------------------+ - $Id: php_imagick.h,v 1.7 2002/12/02 21:25:21 chregu Exp $ + $Id: php_imagick.h,v 1.8 2002/12/05 19:34:34 mcmontero Exp $ */ #ifndef PHP_IMAGICK_H @@ -83,6 +83,8 @@ PHP_FUNCTION( imagick_getwidth ) ; PHP_FUNCTION( imagick_getheight ) ; PHP_FUNCTION( imagick_getmimetype ) ; + PHP_FUNCTION( imagick_getimagedepth ) ; + PHP_FUNCTION( imagick_getnumbercolors ) ; /***** @@ -203,6 +205,18 @@ PHP_FUNCTION( imagick_getlistsize ) ; PHP_FUNCTION( imagick_getlistindex ) ; PHP_FUNCTION( imagick_getimagefromlist ) ; + + /***** + + Transform an image. + + *****/ + + PHP_FUNCTION( imagick_chop ) ; + PHP_FUNCTION( imagick_crop ) ; + PHP_FUNCTION( imagick_flip ) ; + PHP_FUNCTION( imagick_flop ) ; + PHP_FUNCTION( imagick_roll ) ; /***** Index: pear/PECL/imagick/examples/chop.php +++ pear/PECL/imagick/examples/chop.php <?$handle = imagick_readimage( "./image.jpg" ) ; if ( imagick_iserror( $handle ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}if ( !imagick_chop( $handle, 10, 10, 100, 100 ) ) {$reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_chop() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ; }if ( !imagick_writeimage( $handle, "./new_image.jpg" ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_writeimage() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}print "Done!<BR>\n" ;?> Index: pear/PECL/imagick/examples/crop.php +++ pear/PECL/imagick/examples/crop.php <?$handle = imagick_readimage( "./image.jpg" ) ; if ( imagick_iserror( $handle ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}if ( !imagick_crop( $handle, 10, 10, 100, 100 ) ) {$reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_crop() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ; }if ( !imagick_writeimage( $handle, "./new_image.jpg" ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_writeimage() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}print "Done!<BR>\n" ;?> Index: pear/PECL/imagick/examples/flip.php +++ pear/PECL/imagick/examples/flip.php <?$handle = imagick_readimage( "./image.jpg" ) ; if ( imagick_iserror( $handle ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}if ( !imagick_flip( $handle ) ) {$reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_flip() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ; }if ( !imagick_writeimage( $handle, "./new_image.jpg" ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_writeimage() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}print "Done!<BR>\n" ;?> Index: pear/PECL/imagick/examples/flop.php +++ pear/PECL/imagick/examples/flop.php <?$handle = imagick_readimage( "./image.jpg" ) ; if ( imagick_iserror( $handle ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}if ( !imagick_flop( $handle ) ) {$reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_flop() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ; }if ( !imagick_writeimage( $handle, "./new_image.jpg" ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_writeimage() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}print "Done!<BR>\n" ;?> Index: pear/PECL/imagick/examples/getimagedepth.php +++ pear/PECL/imagick/examples/getimagedepth.php <?$handle = imagick_readimage( "./image.jpg" ) ; if ( imagick_iserror( $handle ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}print "Image depth is " . imagick_getimagedepth( $handle ) ." bits<BR>\n" ;?> Index: pear/PECL/imagick/examples/getnumbercolors.php +++ pear/PECL/imagick/examples/getnumbercolors.php <?$handle = imagick_readimage( "./image.jpg" ) ; if ( imagick_iserror( $handle ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}// // If you want a histogram of the color distribution written to a // file, specify the file name as the second parameter. // $numb_colors = imagick_getnumbercolors( $handle, "/dev/null" ) ; if ( imagick_iserror( $handle ) ) {$reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_getnumbercolors failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ; } print "Number of colors: $numb_colors<BR>\n" ; ?> Index: pear/PECL/imagick/examples/roll.php +++ pear/PECL/imagick/examples/roll.php <?$handle = imagick_readimage( "./image.jpg" ) ; if ( imagick_iserror( $handle ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "handle failed!<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}if ( !imagick_roll( $handle, 10, 40) ) {$reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_roll() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ; }if ( !imagick_writeimage( $handle, "./new_image.jpg" ) ) { $reason = imagick_failedreason( $handle ) ; $description = imagick_faileddescription( $handle ) ;print "imagick_writeimage() failed<BR>\nReason: $reason<BR>\nDescription: $description<BR>\n" ;exit ;}print "Done!<BR>\n" ;?> Sounds like an imagick theme tune ;)