Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BUG #1214 #1215

Closed
wants to merge 12 commits into from
Closed
95 changes: 51 additions & 44 deletions ext/image/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ PHP_METHOD(Phalcon_Image_Adapter, resize){
tmp_height = 1;
}

PHALCON_INIT_NVAR(width);
zval_dtor(width);
ZVAL_LONG(width, tmp_width);

PHALCON_INIT_NVAR(height);
zval_dtor(height);
ZVAL_LONG(height, tmp_height);
}

Expand Down 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 All @@ -416,16 +418,16 @@ PHP_METHOD(Phalcon_Image_Adapter, crop){
tmp_height = tmp_max_height;
}

PHALCON_INIT_NVAR(width);
zval_dtor(width);
ZVAL_LONG(width, tmp_width);

PHALCON_INIT_NVAR(height);
zval_dtor(height);
ZVAL_LONG(height, tmp_height);

PHALCON_INIT_NVAR(offset_x);
zval_dtor(offset_x);
ZVAL_LONG(offset_x, tmp_offset_x);

PHALCON_INIT_NVAR(offset_y);
zval_dtor(offset_y);
ZVAL_LONG(offset_y, tmp_offset_y);

phalcon_call_method_p4_noret(this_ptr, "_crop", width, height, offset_x, offset_y);
Expand Down Expand Up @@ -467,7 +469,7 @@ PHP_METHOD(Phalcon_Image_Adapter, rotate){
} while (tmp_degrees < -180);
}

PHALCON_INIT_NVAR(degrees);
zval_dtor(degrees);
ZVAL_LONG(degrees, tmp_degrees);

phalcon_call_method_p1_noret(this_ptr, "_rotate", degrees);
Expand Down Expand Up @@ -565,7 +567,7 @@ PHP_METHOD(Phalcon_Image_Adapter, reflection){
} else if (Z_TYPE_P(height) != IS_LONG || Z_LVAL_P(height) > tmp_image_height) {
PHALCON_SEPARATE_PARAM(height);

PHALCON_INIT_NVAR(height);
zval_dtor(height);
ZVAL_LONG(height, tmp_image_height);
}

Expand All @@ -574,12 +576,13 @@ 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) {
PHALCON_INIT_NVAR(opacity);
if (Z_LVAL_P(opacity) > 100) {
zval_dtor(opacity);
ZVAL_LONG(opacity, 100);
} else if (Z_LVAL_P(opacity) < 0) {
PHALCON_INIT_NVAR(opacity);
zval_dtor(opacity);
ZVAL_LONG(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 @@ -645,15 +648,15 @@ PHP_METHOD(Phalcon_Image_Adapter, watermark){
}
}

PHALCON_INIT_NVAR(offset_x);
zval_dtor(offset_x);
ZVAL_LONG(offset_x, tmp_offset_x);

if (!offset_y) {
tmp_offset_y = (int)(((tmp_image_height - tmp_watermark_height) / 2) + 0.5);
} 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 All @@ -664,7 +667,7 @@ PHP_METHOD(Phalcon_Image_Adapter, watermark){
}
}

PHALCON_INIT_NVAR(offset_y);
zval_dtor(offset_y);
ZVAL_LONG(offset_y, tmp_offset_y);

if (!opacity) {
Expand All @@ -673,7 +676,7 @@ PHP_METHOD(Phalcon_Image_Adapter, watermark){
} else {
PHALCON_SEPARATE_PARAM(opacity);

PHALCON_INIT_NVAR(opacity);
zval_dtor(opacity);
if (phalcon_get_intval(opacity) < 1) {
ZVAL_LONG(opacity, 1);
} else if (phalcon_get_intval(opacity) > 100) {
Expand Down Expand Up @@ -723,12 +726,12 @@ PHP_METHOD(Phalcon_Image_Adapter, text){
}

if (Z_TYPE_P(offset_x) == IS_NULL ) {
PHALCON_INIT_NVAR(offset_x);
zval_dtor(offset_x);
ZVAL_BOOL(offset_x, 0);
}

if (Z_TYPE_P(offset_y) == IS_NULL) {
PHALCON_INIT_NVAR(offset_y);
zval_dtor(offset_y);
ZVAL_BOOL(offset_y, 0);
}

Expand All @@ -737,18 +740,18 @@ PHP_METHOD(Phalcon_Image_Adapter, text){
ZVAL_LONG(opacity, 100);
} else if (Z_TYPE_P(opacity) == IS_NULL) {
PHALCON_SEPARATE_PARAM(opacity);
PHALCON_INIT_NVAR(opacity);
zval_dtor(opacity);
ZVAL_LONG(opacity, 100);
} else {
i = phalcon_get_intval(opacity);

if (i < 1) {
PHALCON_SEPARATE_PARAM(opacity);
PHALCON_INIT_NVAR(opacity);
zval_dtor(opacity);
ZVAL_LONG(opacity, 1);
} else if (i > 100) {
PHALCON_SEPARATE_PARAM(opacity);
PHALCON_INIT_NVAR(opacity);
zval_dtor(opacity);
ZVAL_LONG(opacity, 100);
}
}
Expand All @@ -758,7 +761,7 @@ PHP_METHOD(Phalcon_Image_Adapter, text){
ZVAL_STRING(color, "#000000", 1);
} else if (Z_TYPE_P(color) == IS_NULL) {
PHALCON_SEPARATE_PARAM(color);
PHALCON_INIT_NVAR(color);
zval_dtor(color);
ZVAL_STRING(color, "#000000", 1);
}

Expand All @@ -767,7 +770,7 @@ PHP_METHOD(Phalcon_Image_Adapter, text){
ZVAL_LONG(size, 12);
} else if (Z_TYPE_P(size) == IS_NULL) {
PHALCON_SEPARATE_PARAM(size);
PHALCON_INIT_NVAR(size);
zval_dtor(size);
ZVAL_LONG(size, 12);
}

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 @@ -922,10 +925,10 @@ PHP_METHOD(Phalcon_Image_Adapter, background){
i = phalcon_get_intval(opacity);

if (i < 1) {
PHALCON_INIT_NVAR(opacity);
zval_dtor(opacity);
ZVAL_LONG(opacity, 1);
} else if (i > 100) {
PHALCON_INIT_NVAR(opacity);
zval_dtor(opacity);
ZVAL_LONG(opacity, 100);
}
}
Expand Down Expand Up @@ -956,17 +959,17 @@ PHP_METHOD(Phalcon_Image_Adapter, blur){
} else if (Z_TYPE_P(radius) != IS_LONG) {
PHALCON_SEPARATE_PARAM(radius);

PHALCON_INIT_NVAR(radius);
zval_dtor(radius);
ZVAL_LONG(radius, 1);
} else {
r = phalcon_get_intval(radius);
if (r < 1) {
PHALCON_SEPARATE_PARAM(radius);
PHALCON_INIT_NVAR(radius);
zval_dtor(radius);
ZVAL_LONG(radius, 1);
} else if (r > 100) {
PHALCON_SEPARATE_PARAM(radius);
PHALCON_INIT_NVAR(radius);
zval_dtor(radius);
ZVAL_LONG(radius, 100);
}
}
Expand Down Expand Up @@ -995,12 +998,11 @@ 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_dtor(amount);
ZVAL_LONG(amount, 10);
} else if (phalcon_get_intval(amount) < 2) {
PHALCON_SEPARATE_PARAM(amount);
PHALCON_INIT_NVAR(amount);
zval_dtor(amount);
ZVAL_LONG(amount, 2);
}

Expand Down Expand Up @@ -1036,8 +1038,7 @@ 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_dtor(quality);
ZVAL_LONG(quality, 100);
}
else {
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);

PHALCON_INIT_VAR(constant);
if (zend_get_constant(SL("PATHINFO_EXTENSION"), constant TSRMLS_CC) == FAILURE) {
RETURN_MM();
}

type = phalcon_fetch_nproperty_this(this_ptr, SL("_type"), PH_NOISY_CC);
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
Loading