Skip to content

Commit

Permalink
Merge pull request #1221 from dreamsxin/bug_1214_new
Browse files Browse the repository at this point in the history
Fix BUG #1214
  • Loading branch information
Phalcon committed Sep 12, 2013
2 parents 5eebbe6 + 05e4410 commit 6979900
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 209 deletions.
39 changes: 23 additions & 16 deletions ext/image/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ PHP_METHOD(Phalcon_Image_Adapter, crop){
}

if (!offset_x) {
PHALCON_INIT_VAR(offset_x);
tmp_offset_x = (int)(((tmp_image_width - tmp_width) / 2) + 0.5);
} else {
PHALCON_SEPARATE_PARAM(offset_x);
Expand All @@ -390,6 +391,7 @@ PHP_METHOD(Phalcon_Image_Adapter, crop){
}

if (!offset_y) {
PHALCON_INIT_VAR(offset_y);
tmp_offset_y = (int)(((tmp_image_height - tmp_height) / 2) + 0.5);
} else {
PHALCON_SEPARATE_PARAM(offset_y);
Expand Down Expand Up @@ -574,8 +576,9 @@ PHP_METHOD(Phalcon_Image_Adapter, reflection){
ZVAL_LONG(opacity, 100);
} else {
PHALCON_SEPARATE_PARAM(opacity);
convert_to_long(opacity);

if (Z_TYPE_P(opacity) != IS_LONG || Z_LVAL_P(opacity) > 100) {
if (Z_LVAL_P(opacity) > 100) {
PHALCON_INIT_NVAR(opacity);
ZVAL_LONG(opacity, 100);
} else if (Z_LVAL_P(opacity) < 0) {
Expand Down Expand Up @@ -634,7 +637,7 @@ PHP_METHOD(Phalcon_Image_Adapter, watermark){
} else {
PHALCON_SEPARATE_PARAM(offset_x);
if (Z_TYPE_P(offset_x) == IS_LONG) {
tmp_offset_x = phalcon_get_intval(offset_x);
tmp_offset_x = Z_LVAL_P(offset_x);
if (tmp_offset_x < 0) {
tmp_offset_x = (int)(tmp_image_width - tmp_watermark_width + tmp_offset_x + 0.5);
}
Expand All @@ -653,7 +656,7 @@ PHP_METHOD(Phalcon_Image_Adapter, watermark){
} else {
PHALCON_SEPARATE_PARAM(offset_y);
if (Z_TYPE_P(offset_y) == IS_LONG) {
tmp_offset_y = phalcon_get_intval(offset_y);
tmp_offset_y = Z_LVAL_P(offset_y);
if (tmp_offset_y < 0) {
tmp_offset_y = (int)(tmp_image_height - tmp_watermark_height + tmp_offset_y + 0.5);
}
Expand Down Expand Up @@ -798,7 +801,7 @@ PHP_METHOD(Phalcon_Image_Adapter, text){

ZVAL_STRING(tmp_color, c, 1);

if (Z_STRLEN_P(tmp_color) >= 6) {
if (Z_STRLEN_P(tmp_color) < 6) {
PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "color is not valid");
return;
}
Expand Down Expand Up @@ -995,7 +998,6 @@ PHP_METHOD(Phalcon_Image_Adapter, pixelate){
ZVAL_LONG(amount, 10);
} else if (Z_TYPE_P(amount) != IS_LONG) {
PHALCON_SEPARATE_PARAM(amount);

PHALCON_INIT_NVAR(amount);
ZVAL_LONG(amount, 10);
} else if (phalcon_get_intval(amount) < 2) {
Expand Down Expand Up @@ -1036,7 +1038,6 @@ PHP_METHOD(Phalcon_Image_Adapter, save){
ZVAL_LONG(quality, 100);
} else if (Z_TYPE_P(quality) != IS_LONG) {
PHALCON_SEPARATE_PARAM(quality);

PHALCON_INIT_NVAR(quality);
ZVAL_LONG(quality, 100);
}
Expand Down Expand Up @@ -1106,28 +1107,34 @@ PHP_METHOD(Phalcon_Image_Adapter, save){
*/
PHP_METHOD(Phalcon_Image_Adapter, render){

zval *ext = NULL, *quality = NULL, *type, *include_dot;
zval *ext = NULL, *quality = NULL, *constant, *file;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 0, 2, &ext, &quality);

if (!ext) {
PHALCON_INIT_VAR(include_dot);
ZVAL_FALSE(include_dot);
PHALCON_INIT_NVAR(ext);
file = phalcon_fetch_nproperty_this(this_ptr, SL("_file"), PH_NOISY_CC);

type = phalcon_fetch_nproperty_this(this_ptr, SL("_type"), PH_NOISY_CC);
PHALCON_INIT_VAR(constant);
if (zend_get_constant(SL("PATHINFO_EXTENSION"), constant TSRMLS_CC) == FAILURE) {
RETURN_MM();
}

phalcon_call_func_p2(ext, "pathinfo", file, constant);

/**
* @todo image_type_to_extension is from GD
*/
PHALCON_INIT_VAR(ext);
phalcon_call_func_p2(ext, "image_type_to_extension", type, include_dot);
if (!PHALCON_IS_NOT_EMPTY(ext)) {
ZVAL_STRING(ext, "png", 1);
}
}

if (!quality || Z_TYPE_P(quality) != IS_LONG) {
if (!quality) {
PHALCON_INIT_VAR(quality);
ZVAL_LONG(quality, 100);
} else if (Z_TYPE_P(quality) != IS_LONG) {
PHALCON_SEPARATE_PARAM(quality);
convert_to_long(quality);
}

phalcon_call_method_p2(return_value, this_ptr, "_render", ext, quality);
Expand Down
39 changes: 22 additions & 17 deletions ext/image/adapter/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _resize) {
}
#else
PHALCON_OBS_NVAR(tmp_image);
PHALCON_CALL_FUNCTION(tmp_image, &tmp_image, "imagescale", 3, tmp_image, width, height);
PHALCON_CALL_FUNCTION(tmp_image, &tmp_image, "imagescale", 3, image, width, height);

phalcon_call_func_p1_noret("imagedestroy", image);
phalcon_update_property_this(this_ptr, SL("_image"), tmp_image TSRMLS_CC);
Expand Down Expand Up @@ -443,13 +443,19 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _crop) {
#else
PHALCON_INIT_VAR(rect);
array_init_size(rect, 4);
phalcon_array_append(&rect, offset_x, 0);
phalcon_array_append(&rect, offset_y, 0);
phalcon_array_append(&rect, width, 0);
phalcon_array_append(&rect, height, 0);
phalcon_array_update_string(&rect, SL("x"), &offset_x, PH_COPY);
phalcon_array_update_string(&rect, SL("y"), &offset_y, PH_COPY);
phalcon_array_update_string(&rect, SL("width"), &width, PH_COPY);
phalcon_array_update_string(&rect, SL("height"), &height, PH_COPY);

PHALCON_OBS_VAR(tmp_image);
PHALCON_CALL_FUNCTION(tmp_image, &tmp_image, "imagecrop", 2, image, rect);

phalcon_call_func_p1_noret("imagedestroy", image);
phalcon_update_property_this(this_ptr, SL("_image"), tmp_image TSRMLS_CC);

phalcon_update_property_this(this_ptr, SL("_width"), width TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_height"), height TSRMLS_CC);
#endif

PHALCON_MM_RESTORE();
Expand Down Expand Up @@ -524,8 +530,9 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _rotate) {
PHP_METHOD(Phalcon_Image_Adapter_GD, _flip) {

zval *direction;
zval *image = NULL, *flipped_image;
zval *image = NULL;
#if PHP_VERSION_ID < 50500
zval *flipped_image;
zval *width, *height;
zval *dst_x = NULL, *dst_y = NULL, *src_x = NULL, *src_y = NULL, *src_width = NULL, *src_height = NULL;
int w, h, x, y;
Expand Down Expand Up @@ -596,6 +603,9 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _flip) {
PHALCON_CALL_FUNCTION(NULL, NULL, "imagecopy", 8, flipped_image, image, dst_x, dst_y, src_x, src_y, src_width, src_height);
}
}

phalcon_call_func_p1_noret("imagedestroy", image);
phalcon_update_property_this(this_ptr, SL("_image"), flipped_image TSRMLS_CC);
#else
PHALCON_INIT_VAR(mode);
if (Z_LVAL_P(direction) == PHALCON_IMAGE_HORIZONTAL) {
Expand All @@ -607,12 +617,9 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _flip) {
RETURN_MM();
}
}
PHALCON_OBS_VAR(flipped_image);
PHALCON_CALL_FUNCTION(flipped_image, &flipped_image, "imageflip", 2, image, mode);
#endif

phalcon_call_func_p1_noret("imagedestroy", image);
phalcon_update_property_this(this_ptr, SL("_image"), flipped_image TSRMLS_CC);
PHALCON_CALL_FUNCTION(NULL, NULL, "imageflip", 2, image, mode);
#endif

PHALCON_MM_RESTORE();
}
Expand Down Expand Up @@ -767,7 +774,6 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _reflection) {
ZVAL_LONG(dst, 0);

PHALCON_CALL_FUNCTION(NULL, NULL, "imagecopy", 8, reflection, image, dst, dst, dst, dst, image_width, image_height);
phalcon_update_property_this(this_ptr, SL("_image"), reflection TSRMLS_CC);

PHALCON_INIT_NVAR(tmp);
ZVAL_LONG(tmp, 1);
Expand Down Expand Up @@ -1080,7 +1086,7 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _text) {
phalcon_call_func_p5_ex(color, &color, "imagecolorallocatealpha", image, r, g, b, opacity);

phalcon_call_func_p6_noret("imagestring", image, size, offset_x, offset_y, text, color);
}
}

PHALCON_MM_RESTORE();
}
Expand Down Expand Up @@ -1113,7 +1119,6 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _mask){
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);
Expand All @@ -1128,7 +1133,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_call_func_p2_noret("imagesavealpha", newimage, saveflag);

PHALCON_INIT_VAR(c);
Expand All @@ -1148,8 +1152,9 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _mask){
phalcon_call_func_p2_ex(temp_image, &temp_image, "imagecreatetruecolor", image_width, image_height);

PHALCON_CALL_FUNCTION(NULL, NULL, "imagecopyresampled", 10, temp_image, mask_image, c, c, c, c, image_width, image_height, mask_image_width, mask_image_height);

phalcon_call_func_p1_noret("imagedestroy", mask_image);

PHALCON_CPY_WRT(mask_image, temp_image);
}

Expand Down Expand Up @@ -1204,9 +1209,9 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _mask){
}
}

phalcon_update_property_this(this_ptr, SL("_image"), newimage TSRMLS_CC);
phalcon_call_func_p1_noret("imagedestroy", image);
phalcon_call_func_p1_noret("imagedestroy", mask_image);
phalcon_update_property_this(this_ptr, SL("_image"), newimage TSRMLS_CC);

PHALCON_MM_RESTORE();
}
Expand Down
42 changes: 25 additions & 17 deletions ext/image/adapter/imagick.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, __construct){
phalcon_call_method(type, im, "getImageType");
phalcon_update_property_this(this_ptr, SL("_type"), type TSRMLS_CC);


PHALCON_INIT_VAR(format);
phalcon_call_method(format, im, "getImageFormat");

Expand Down Expand Up @@ -370,7 +369,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _liquidRescale){
*/
PHP_METHOD(Phalcon_Image_Adapter_Imagick, _crop) {

zval *width, *height, *offset_x, *offset_y;
zval *width, *height, *offset_x, *offset_y, *w, *h;
zval *im, *ret = NULL, *index, *next = NULL, *type, *tmp;

PHALCON_MM_GROW();
Expand Down Expand Up @@ -418,6 +417,15 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _crop) {
phalcon_call_method_p4_noret(im, "setImagePage", width, height, tmp, tmp);
}

PHALCON_INIT_VAR(w);
phalcon_call_method(w, im, "getImageWidth");

PHALCON_INIT_VAR(h);
phalcon_call_method(h, im, "getImageHeight");

phalcon_update_property_this(this_ptr, SL("_width"), w TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_height"), h TSRMLS_CC);

PHALCON_MM_RESTORE();
}

Expand All @@ -436,6 +444,8 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _rotate) {

phalcon_fetch_params(1, 1, 0, &degrees);

ce0 = zend_fetch_class(SL("ImagickPixel"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

PHALCON_OBS_VAR(im);
phalcon_read_property_this(&im, this_ptr, SL("_image"), PH_NOISY_CC);

Expand All @@ -445,8 +455,6 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _rotate) {
PHALCON_INIT_VAR(tmp);
ZVAL_LONG(tmp, 0);

ce0 = zend_fetch_class(SL("ImagickPixel"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

PHALCON_INIT_VAR(background);
object_init_ex(background, ce0);
if (phalcon_has_constructor(background TSRMLS_CC)) {
Expand Down Expand Up @@ -655,6 +663,7 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _reflection) {
phalcon_fetch_params(1, 3, 0, &height, &opacity, &fade_in);

ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
ce1 = zend_fetch_class(SL("ImagickPixel"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

PHALCON_OBS_VAR(im);
phalcon_read_property_this(&im, this_ptr, SL("_image"), PH_NOISY_CC);
Expand Down Expand Up @@ -781,8 +790,6 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _reflection) {
PHALCON_INIT_VAR(h0);
ZVAL_LONG(h0, ini_h);

ce1 = zend_fetch_class(SL("ImagickPixel"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

PHALCON_INIT_VAR(background);
object_init_ex(background, ce1);
if (phalcon_has_constructor(background TSRMLS_CC)) {
Expand Down Expand Up @@ -906,16 +913,15 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _watermark) {

phalcon_fetch_params(1, 4, 0, &watermark_image, &offset_x, &offset_y, &opacity);

ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

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");
Expand Down Expand Up @@ -1015,6 +1021,10 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _text) {

phalcon_fetch_params(1, 9, 0, &text, &offset_x, &offset_y, &opacity, &r, &g, &b, &size, &fontfile);

ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
ce1 = zend_fetch_class(SL("ImagickDraw"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
ce2 = zend_fetch_class(SL("ImagickPixel"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

if (!offset_x) {
PHALCON_INIT_VAR(offset_x);
} else {
Expand All @@ -1027,10 +1037,6 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _text) {
PHALCON_SEPARATE_PARAM(offset_y);
}

ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
ce1 = zend_fetch_class(SL("ImagickDraw"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);
ce2 = zend_fetch_class(SL("ImagickPixel"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

PHALCON_OBS_VAR(im);
phalcon_read_property_this(&im, this_ptr, SL("_image"), PH_NOISY_CC);

Expand Down Expand Up @@ -1250,11 +1256,14 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask){

phalcon_fetch_params(1, 1, 0, &mask);

ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

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);
object_init_ex(mask_im, ce0);
if (phalcon_has_constructor(mask_im TSRMLS_CC)) {
Expand All @@ -1275,8 +1284,6 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask){
PHALCON_INIT_VAR(tmp);
ZVAL_LONG(tmp, 0);

ce0 = zend_fetch_class(SL("Imagick"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC);

PHALCON_INIT_VAR(composite);
phalcon_get_class_constant(composite, ce0, SS("COMPOSITE_DSTIN") TSRMLS_CC);

Expand All @@ -1293,13 +1300,14 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _mask){
PHALCON_INIT_NVAR(next);
phalcon_call_method(next, im, "nextImage");
} while (zend_is_true(next));
} else {
}

else {
phalcon_call_method_p1_noret(im, "setImageMatte", matte);
phalcon_call_method_p4_noret(im, "compositeImage", mask_im, composite, tmp, tmp);
}

phalcon_call_method_noret(mask_im, "clear");
phalcon_call_method_noret(mask_im, "destroy");

PHALCON_MM_RESTORE();
}
Expand Down
Loading

0 comments on commit 6979900

Please sign in to comment.