From 52514740d85d7e2c4febd011f7b92b574cf34f06 Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Sat, 7 Sep 2013 08:21:36 +0800 Subject: [PATCH 1/4] Updated --- ext/image/adapter/gd.c | 22 ++++++++++++---------- ext/image/adapter/imagick.c | 36 +++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/ext/image/adapter/gd.c b/ext/image/adapter/gd.c index 61c778b672c..e439824fc2b 100644 --- a/ext/image/adapter/gd.c +++ b/ext/image/adapter/gd.c @@ -827,7 +827,7 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _reflection) { PHP_METHOD(Phalcon_Image_Adapter_GD, _watermark) { zval *watermark, *offset_x = NULL, *offset_y = NULL, *opacity = NULL, *op = NULL; - zval *image, *overlay, *saveflag, *width, *height, *color, *tmp = NULL, *effect, *blendmode, *ret; + zval *image, *overlay, *blob, *saveflag, *width, *height, *color, *tmp = NULL, *effect, *blendmode, *ret; int int_opacity; double num; @@ -835,12 +835,13 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _watermark) { phalcon_fetch_params(1, 4, 0, &watermark, &offset_x, &offset_y, &opacity); - PHALCON_SEPARATE_PARAM(watermark); - image = phalcon_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC); - PHALCON_OBS_VAR(overlay); - phalcon_call_method_p0_ex(overlay, &overlay, watermark, "getImage"); + PHALCON_INIT_VAR(blob); + phalcon_call_method(blob, watermark, "render"); + + PHALCON_INIT_VAR(overlay); + phalcon_call_func_p2_noret(overlay, "imagecreatefromstring", blob); PHALCON_INIT_VAR(saveflag); ZVAL_TRUE(saveflag); @@ -1092,7 +1093,7 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _text) { */ PHP_METHOD(Phalcon_Image_Adapter_GD, _mask){ - zval *mask, *image, *mask_image, *mask_image_width, *mask_image_height, *newimage, *image_width, *image_height, *saveflag, *color, *c, *alpha = NULL; + zval *mask, *image, *mask_image, *blob, *mask_image_width, *mask_image_height, *newimage, *image_width, *image_height, *saveflag, *color, *c, *alpha = NULL; zval *r = NULL, *g = NULL, *b = NULL, *index = NULL, *index2 = NULL, *zx = NULL, *zy = NULL, *red = NULL; zval *temp_image; int x, y, w, h, i; @@ -1100,13 +1101,14 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _mask){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &mask); - - PHALCON_SEPARATE_PARAM(mask); image = phalcon_fetch_nproperty_this(this_ptr, SL("_image"), PH_NOISY_CC); - PHALCON_OBS_VAR(mask_image); - phalcon_call_method_p0_ex(mask_image, &mask_image, mask, "getImage"); + PHALCON_INIT_VAR(blob); + phalcon_call_method(blob, mask, "render"); + + PHALCON_INIT_VAR(mask_image); + phalcon_call_func_p2_noret(mask_image, "imagecreatefromstring", blob); PHALCON_OBS_VAR(mask_image_width); phalcon_call_func_p1_ex(mask_image_width, &mask_image_width, "imagesx", mask_image); diff --git a/ext/image/adapter/imagick.c b/ext/image/adapter/imagick.c index 3dd5291693c..4ab6ca8eed7 100644 --- a/ext/image/adapter/imagick.c +++ b/ext/image/adapter/imagick.c @@ -898,7 +898,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _reflection) { PHP_METHOD(Phalcon_Image_Adapter_Imagick, _watermark) { zval *watermark_image, *offset_x, *offset_y, *opacity, *op =NULL; - zval *im, *watermark, *ret = NULL, *channel, *op_constant = NULL, *composite, *index, *next = NULL, *type; + zval *im, *watermark, *realpath, *blob, *ret = NULL, *channel, *op_constant = NULL, *composite, *index, *next = NULL, *type; zend_class_entry *ce0; double num; @@ -906,18 +906,28 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _watermark) { phalcon_fetch_params(1, 4, 0, &watermark_image, &offset_x, &offset_y, &opacity); - PHALCON_SEPARATE_PARAM(watermark_image); - PHALCON_OBS_VAR(im); phalcon_read_property_this(&im, this_ptr, SL("_image"), PH_NOISY_CC); PHALCON_OBS_VAR(type); phalcon_read_property_this(&type, this_ptr, SL("_type"), PH_NOISY_CC); + ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(watermark); phalcon_call_method(watermark, watermark_image, "getImage"); + object_init_ex(watermark, ce0); + if (phalcon_has_constructor(watermark TSRMLS_CC)) { + phalcon_call_method_noret(watermark, "__construct"); + } - ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(realpath); + phalcon_call_method(realpath, watermark_image, "getRealPath"); + + PHALCON_INIT_VAR(blob); + phalcon_call_method(blob, watermark_image, "render"); + + phalcon_call_method_p2_noret(watermark, "readImageBlob", blob, realpath); PHALCON_INIT_VAR(channel); phalcon_get_class_constant(channel, ce0, SS("ALPHACHANNEL_ACTIVATE") TSRMLS_CC); @@ -1233,23 +1243,31 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _text) { */ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask){ - zval *mask, *im, *mask_im, *matte, *composite, *tmp, *index, *next = NULL, *type; + zval *mask, *im, *mask_im, *realpath, *blod, *matte, *composite, *tmp, *index, *next = NULL, *type; zend_class_entry *ce0; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &mask); - - PHALCON_SEPARATE_PARAM(mask); PHALCON_OBS_VAR(im); phalcon_read_property_this(&im, this_ptr, SL("_image"), PH_NOISY_CC); PHALCON_OBS_VAR(type); phalcon_read_property_this(&type, this_ptr, SL("_type"), PH_NOISY_CC); - PHALCON_INIT_VAR(mask_im); - phalcon_call_method(mask_im, mask, "getImage"); + object_init_ex(mask_im, ce0); + if (phalcon_has_constructor(mask_im TSRMLS_CC)) { + phalcon_call_method_noret(mask_im, "__construct"); + } + + PHALCON_INIT_VAR(realpath); + phalcon_call_method(realpath, mask, "getRealPath"); + + PHALCON_INIT_VAR(blob); + phalcon_call_method(blob, mask, "render"); + + phalcon_call_method_p2_noret(mask_im, "readImageBlob", blob, realpath); PHALCON_INIT_VAR(matte); ZVAL_LONG(matte, 1); From 5eb328836e9bf6edd0074047dab18f4714fbe23b Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Sat, 7 Sep 2013 08:29:59 +0800 Subject: [PATCH 2/4] Updated --- ext/image/adapter/gd.c | 12 ++++++++---- ext/image/adapter/imagick.c | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ext/image/adapter/gd.c b/ext/image/adapter/gd.c index e439824fc2b..a4ba5ef1fc7 100644 --- a/ext/image/adapter/gd.c +++ b/ext/image/adapter/gd.c @@ -841,7 +841,7 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _watermark) { phalcon_call_method(blob, watermark, "render"); PHALCON_INIT_VAR(overlay); - phalcon_call_func_p2_noret(overlay, "imagecreatefromstring", blob); + phalcon_call_func_p1(overlay, "imagecreatefromstring", blob); PHALCON_INIT_VAR(saveflag); ZVAL_TRUE(saveflag); @@ -1108,7 +1108,13 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _mask){ phalcon_call_method(blob, mask, "render"); PHALCON_INIT_VAR(mask_image); - phalcon_call_func_p2_noret(mask_image, "imagecreatefromstring", blob); + phalcon_call_func_p1(mask_image, "imagecreatefromstring", blob); + + PHALCON_INIT_VAR(saveflag); + ZVAL_TRUE(saveflag); + + PHALCON_INIT_VAR(mask_image); + phalcon_call_func_p2_noret("imagesavealpha", mask_image, saveflag); PHALCON_OBS_VAR(mask_image_width); phalcon_call_func_p1_ex(mask_image_width, &mask_image_width, "imagesx", mask_image); @@ -1122,8 +1128,6 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _mask){ PHALCON_OBS_VAR(newimage); phalcon_call_method_p2_ex(newimage, &newimage, this_ptr, "_create", image_width, image_height); - PHALCON_INIT_VAR(saveflag); - ZVAL_TRUE(saveflag); phalcon_call_func_p2_noret("imagesavealpha", newimage, saveflag); diff --git a/ext/image/adapter/imagick.c b/ext/image/adapter/imagick.c index 4ab6ca8eed7..eb47d6a2179 100644 --- a/ext/image/adapter/imagick.c +++ b/ext/image/adapter/imagick.c @@ -927,7 +927,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _watermark) { PHALCON_INIT_VAR(blob); phalcon_call_method(blob, watermark_image, "render"); - phalcon_call_method_p2_noret(watermark, "readImageBlob", blob, realpath); + phalcon_call_method_p2(watermark, "readImageBlob", blob, realpath); PHALCON_INIT_VAR(channel); phalcon_get_class_constant(channel, ce0, SS("ALPHACHANNEL_ACTIVATE") TSRMLS_CC); @@ -1267,7 +1267,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask){ PHALCON_INIT_VAR(blob); phalcon_call_method(blob, mask, "render"); - phalcon_call_method_p2_noret(mask_im, "readImageBlob", blob, realpath); + phalcon_call_method_p2(mask_im, "readImageBlob", blob, realpath); PHALCON_INIT_VAR(matte); ZVAL_LONG(matte, 1); From 5110afa5ea4d968bb0d0311f776a96fc5e13bb1c Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Sat, 7 Sep 2013 09:06:51 +0800 Subject: [PATCH 3/4] Fix bug --- ext/image/adapter/imagick.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/image/adapter/imagick.c b/ext/image/adapter/imagick.c index eb47d6a2179..bf8f6d6c994 100644 --- a/ext/image/adapter/imagick.c +++ b/ext/image/adapter/imagick.c @@ -927,7 +927,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _watermark) { PHALCON_INIT_VAR(blob); phalcon_call_method(blob, watermark_image, "render"); - phalcon_call_method_p2(watermark, "readImageBlob", blob, realpath); + phalcon_call_method_p2_noret(watermark, "readImageBlob", blob, realpath); PHALCON_INIT_VAR(channel); phalcon_get_class_constant(channel, ce0, SS("ALPHACHANNEL_ACTIVATE") TSRMLS_CC); @@ -1243,7 +1243,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _text) { */ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask){ - zval *mask, *im, *mask_im, *realpath, *blod, *matte, *composite, *tmp, *index, *next = NULL, *type; + zval *mask, *im, *mask_im, *realpath, *blob, *matte, *composite, *tmp, *index, *next = NULL, *type; zend_class_entry *ce0; PHALCON_MM_GROW(); @@ -1267,7 +1267,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask){ PHALCON_INIT_VAR(blob); phalcon_call_method(blob, mask, "render"); - phalcon_call_method_p2(mask_im, "readImageBlob", blob, realpath); + phalcon_call_method_p2_noret(mask_im, "readImageBlob", blob, realpath); PHALCON_INIT_VAR(matte); ZVAL_LONG(matte, 1); From 7fe0502b18342b3ddb05a3e463fe1be7ab1aaabc Mon Sep 17 00:00:00 2001 From: dreamsxin Date: Sat, 7 Sep 2013 09:28:55 +0800 Subject: [PATCH 4/4] Updated ImageTest.php --- unit-tests/ImageTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/unit-tests/ImageTest.php b/unit-tests/ImageTest.php index 503cfbc8e0f..e0b9a20cfdb 100644 --- a/unit-tests/ImageTest.php +++ b/unit-tests/ImageTest.php @@ -50,6 +50,11 @@ public function testGD() $image->resize(200, 200)->save('unit-tests/assets/production/gd-resize.jpg'); $this->assertTrue(file_exists('unit-tests/assets/production/gd-resize.jpg')); + $width = imagesx('unit-tests/assets/production/gd-resize.jpg'); + $height = imagesy('unit-tests/assets/production/gd-resize.jpg'); + $this->assertTrue($width <= 200); + $this->assertTrue($height <= 200); + // Resize to 200x200 pixels, keeping aspect ratio //$image->resize(200, 200, Phalcon\Image::INVERSE); @@ -63,9 +68,15 @@ public function testGD() //$image->resize(200, 500, Phalcon\Image::NONE); // Crop the image to 200x200 pixels, from the center + $image = new Phalcon\Image\Adapter\GD('unit-tests/assets/phalconphp.jpg'); $image->crop(200, 200)->save('unit-tests/assets/production/gd-crop.jpg'); $this->assertTrue(file_exists('unit-tests/assets/production/gd-crop.jpg')); + $width = imagesx('unit-tests/assets/production/gd-crop.jpg'); + $height = imagesy('unit-tests/assets/production/gd-crop.jpg'); + $this->assertEquals($width, 200); + $this->assertEquals($height, 200); + // Rotate 45 degrees clockwise $image->rotate(45)->save('unit-tests/assets/production/gd-rotate.jpg');