CVS update: php3/functions

From: Date: Thu, 25 Feb 1999 17:49:25 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-4290@lists.php.net to get a copy of this message
Date: Thursday February 25, 1999 @ 12:49 Author: thies Update of /repository/php3/functions In directory asf:/u/temp/cvs-serv6266/functions Modified Files: magick.c Log Message: added scaling Index: php3/functions/magick.c diff -c php3/functions/magick.c:1.3 php3/functions/magick.c:1.4 *** php3/functions/magick.c:1.3 Thu Feb 25 11:31:34 1999 --- php3/functions/magick.c Thu Feb 25 12:49:24 1999 *************** *** 27,39 **** +----------------------------------------------------------------------+ */ ! /* $Id: magick.c,v 1.3 1999/02/25 16:31:34 thies Exp $ */ /* TODO list: * * - make this thing work! ! * - error and warning handler ! * - redirect stdout * - Error/Warning Handlers are dodgy.... */ --- 27,38 ---- +----------------------------------------------------------------------+ */ ! /* $Id: magick.c,v 1.4 1999/02/25 17:49:24 thies Exp $ */ /* TODO list: * * - make this thing work! ! * - redirect stdout to phpwrite for $img->save("gif:-"); * - Error/Warning Handlers are dodgy.... */ *************** *** 63,68 **** --- 62,68 ---- #include "magick.h" + #define MAGICK_IMAGE_TYPE(x) ((x)==MAGICK_GLOBAL(php3_magick_module).le_image) typedef struct { *************** *** 153,159 **** void php3_ReadMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_SaveMagick(INTERNAL_FUNCTION_PARAMETERS); ! void php3_SizeMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_FreeMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_MagickDebug(INTERNAL_FUNCTION_PARAMETERS); --- 153,159 ---- void php3_ReadMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_SaveMagick(INTERNAL_FUNCTION_PARAMETERS); ! void php3_ScaleMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_FreeMagick(INTERNAL_FUNCTION_PARAMETERS); void php3_MagickDebug(INTERNAL_FUNCTION_PARAMETERS); *************** *** 164,175 **** #define D_IMAGEINFO 1<<1 #define D_IMAGE 1<<2 function_entry magick_functions[] = { {"readmagick", php3_ReadMagick, NULL}, {"savemagick", php3_SaveMagick, NULL}, {"freemagick", php3_FreeMagick, NULL}, ! {"sizemagick", php3_SizeMagick, NULL}, {"magickdebug", php3_MagickDebug, NULL}, {NULL, NULL, NULL} }; --- 164,176 ---- #define D_IMAGEINFO 1<<1 #define D_IMAGE 1<<2 + #define D_PROCESS 1<<3 function_entry magick_functions[] = { {"readmagick", php3_ReadMagick, NULL}, {"savemagick", php3_SaveMagick, NULL}, {"freemagick", php3_FreeMagick, NULL}, ! {"scalemagick", php3_ScaleMagick, NULL}, {"magickdebug", php3_MagickDebug, NULL}, {NULL, NULL, NULL} }; *************** *** 381,387 **** error_number? "]" : ""); } /* }}} */ - /************************* EXTENSION FUNCTIONS *************************/ /* {{{ proto object ReadMagick(string filename) Load an Image */ --- 382,387 ---- *************** *** 432,438 **** image->id = php3_list_insert(image, MAGICK_GLOBAL(php3_magick_module).le_image); magick_debug(D_IMAGE,"New Image %d -> %x",image->id,image->Image); ! object_init(return_value); add_property_long(return_value, "_imageinfo", imageinfo->id); add_property_long(return_value, "_image", image->id); --- 432,438 ---- image->id = php3_list_insert(image, MAGICK_GLOBAL(php3_magick_module).le_image); magick_debug(D_IMAGE,"New Image %d -> %x",image->id,image->Image); ! object_init(return_value); add_property_long(return_value, "_imageinfo", imageinfo->id); add_property_long(return_value, "_image", image->id); *************** *** 448,455 **** add_property_long(return_value, "total_colors", image->Image->total_colors); ! add_method(return_value, "save", php3_SaveMagick); ! add_method(return_value, "free", php3_FreeMagick); } /* }}} */ --- 448,456 ---- add_property_long(return_value, "total_colors", image->Image->total_colors); ! add_method(return_value, "save", php3_SaveMagick); ! add_method(return_value, "free", php3_FreeMagick); ! add_method(return_value, "scale", php3_ScaleMagick); } /* }}} */ *************** *** 526,535 **** RETURN_TRUE; } /* }}} */ ! /* {{{ proto int SizeMagick(object image) ! Crop an Image */ ! void php3_SizeMagick(INTERNAL_FUNCTION_PARAMETERS) { RETURN_TRUE; } /* }}} */ --- 527,614 ---- RETURN_TRUE; } /* }}} */ ! /* {{{ proto int ScaleMagick(object image) ! Scale an Image */ ! void php3_ScaleMagick(INTERNAL_FUNCTION_PARAMETERS) { + pval *id, *pimage, *oneval = 0, *colval, *rowval; + magick_image *image; + Image *newimage; + double cols = 0, rows = 0, one = 0, curcols, currows; + MAGICK_TLS_VARS; + + if (getThis(&id) == FAILURE) { + RETURN_FALSE; + } + + if (_php3_hash_find(id->value.ht, "_image", sizeof("_image"), (void **)&pimage) == FAILURE) { + php3_error(E_WARNING, "unable to find my image property"); + RETURN_FALSE; + } + + image = magick_get_image(pimage->value.lval, "ScaleMagick", list); + if (image == NULL) { + RETURN_FALSE; + } + + if (getParameters(ht, 2, &colval,&rowval) == SUCCESS) { + convert_to_long(colval); + convert_to_long(rowval); + cols = colval->value.lval; + rows = rowval->value.lval; + if ((cols == 0) && (rows == 0)) { + php3_error(E_WARNING, "Cannot set size to 0/0"); + RETURN_FALSE; + } else if ((cols < 0) || (rows < 0)) { + php3_error(E_WARNING, "Cannot set size to negative values"); + RETURN_FALSE; + } + } else if (getParameters(ht, 1, &oneval) == SUCCESS) { + convert_to_long(oneval); + one = oneval->value.lval; + if (one <= 0) { + php3_error(E_WARNING, "Cannot set size to %d",(int) one); + RETURN_FALSE; + } + } else { + WRONG_PARAM_COUNT; + } + + curcols = image->Image->columns; + currows = image->Image->rows; + + if (oneval) { + if (curcols > currows) { + rows = currows / (curcols / one); + cols = one; + } else { + cols = curcols / (currows / one); + rows = one; + } + } else if (cols == 0) { + cols = curcols * (rows / currows); + } else if (rows == 0) { + rows = currows * (cols / curcols); + } + + magick_debug(D_PROCESS,"Scale %d (%d,%d) to (%d,%d)", + image->id, + image->Image->columns,image->Image->rows, + (int) cols, (int) rows); + + newimage = ScaleImage(image->Image,cols,rows); + + + if (newimage== NULL) { + RETURN_FALSE; + } + + /* need to correct the structure members...*/ + + DestroyImage(image->Image); /*XXX we don't want you anymore.... or do we???? */ + + image->Image = newimage; + RETURN_TRUE; } /* }}} */ -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#4290) next »