/* {{{ proto array ImagickPixel::getColorAsString(void ) Returns the color as a string */ PHP_METHOD(imagickpixel, getcolorasstring) { php_imagickpixel_object *internp; char *color_string; if (zend_parse_parameters_none() == FAILURE) { return; } internp = Z_IMAGICKPIXEL_P(getThis()); color_string = PixelGetColorAsString(internp->pixel_wand); IM_ZVAL_STRING(return_value, color_string); IMAGICK_FREE_MAGICK_MEMORY(color_string); return; }
/* {{{ proto array ImagickPixel::getColorAsString(void ) Returns the color as a string */ PHP_METHOD(imagickpixel, getcolorasstring) { php_imagickpixel_object *internp; char *color_string; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } internp = (php_imagickpixel_object *)zend_object_store_get_object(getThis() TSRMLS_CC); color_string = PixelGetColorAsString(internp->pixel_wand); ZVAL_STRING(return_value, color_string, 1); IMAGICK_FREE_MEMORY(char *, color_string); return; }
/* {{{ proto array GmagickPixel::getColor([boolean as_array = false, normalise_array = false]) Returns the color of the pixel */ PHP_METHOD(gmagickpixel, getcolor) { php_gmagickpixel_object *internp; zend_bool as_array = 0, normalise_array = 0; /* Parse parameters given to function */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bb", &as_array, &normalise_array) == FAILURE) { return; } internp = Z_GMAGICKPIXEL_OBJ_P(getThis()); if (!as_array) { char *buffer, *color_string; int len; color_string = PixelGetColorAsString(internp->pixel_wand); len = spprintf(&buffer, 50, "rgb(%s)", color_string); GMAGICK_FREE_MEMORY(char *, color_string); RETVAL_STRINGL(buffer, len); efree(buffer); return; } else { array_init(return_value); if (normalise_array == 1) { add_assoc_double(return_value, "r", PixelGetRed(internp->pixel_wand)); add_assoc_double(return_value, "g", PixelGetGreen(internp->pixel_wand)); add_assoc_double(return_value, "b", PixelGetBlue(internp->pixel_wand)); } else { double red, green, blue; red = PixelGetRed(internp->pixel_wand ) * 255; green = PixelGetGreen(internp->pixel_wand ) * 255; blue = PixelGetBlue(internp->pixel_wand ) * 255; add_assoc_long(return_value, "r", (int)(red > 0.0 ? red + 0.5 : red - 0.5)); add_assoc_long(return_value, "g", (int)(green > 0.0 ? green + 0.5 : green - 0.5)); add_assoc_long(return_value, "b", (int)(blue > 0.0 ? blue + 0.5 : blue - 0.5)); } return; } }
static String HHVM_METHOD(ImagickPixel, getColorAsString) { auto wand = getPixelWandResource(this_); return convertMagickString(PixelGetColorAsString(wand->getWand())); }