Skip to content

Commit

Permalink
Merge pull request #1206 from dreamsxin/image_1.3.0_updated
Browse files Browse the repository at this point in the history
Image 1.3.0 updated
  • Loading branch information
Phalcon committed Sep 7, 2013
2 parents b6729c4 + 7fe0502 commit 6fabb3f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
30 changes: 18 additions & 12 deletions ext/image/adapter/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,20 +827,21 @@ 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;

PHALCON_MM_GROW();

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_p1(overlay, "imagecreatefromstring", blob);

PHALCON_INIT_VAR(saveflag);
ZVAL_TRUE(saveflag);
Expand Down Expand Up @@ -1092,21 +1093,28 @@ 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;

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_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);
Expand All @@ -1120,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);

Expand Down
36 changes: 27 additions & 9 deletions ext/image/adapter/imagick.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,26 +898,36 @@ 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;

PHALCON_MM_GROW();

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);
Expand Down Expand Up @@ -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, *blob, *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);
Expand Down
11 changes: 11 additions & 0 deletions unit-tests/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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');
Expand Down

0 comments on commit 6fabb3f

Please sign in to comment.