Skip to content

Commit

Permalink
Merge pull request #1063 from dreamsxin/image_updated
Browse files Browse the repository at this point in the history
Image updated: add master option TENSILE
  • Loading branch information
Phalcon committed Aug 12, 2013
2 parents e42af73 + 31d6f95 commit af2853d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 88 deletions.
1 change: 1 addition & 0 deletions ext/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PHALCON_INIT_CLASS(Phalcon_Image){
zend_declare_class_constant_long(phalcon_image_ce, SL("AUTO"), 4 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("INVERSE"), 5 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("PRECISE"), 6 TSRMLS_CC);
zend_declare_class_constant_long(phalcon_image_ce, SL("TENSILE"), 7 TSRMLS_CC);

// Flipping directions
zend_declare_class_constant_long(phalcon_image_ce, SL("HORIZONTAL"), 11 TSRMLS_CC);
Expand Down
179 changes: 97 additions & 82 deletions ext/image/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ PHP_METHOD(Phalcon_Image_Adapter, getImage){
*
* @param int $width new width
* @param int $height new height
* @param int $master master dimension
* @param int $master master dimension, if master equal TENSILE, the width and height must be input
* @return Phalcon\Image\Adapter
*/
PHP_METHOD(Phalcon_Image_Adapter, resize){
Expand All @@ -210,122 +210,137 @@ PHP_METHOD(Phalcon_Image_Adapter, resize){

phalcon_fetch_params(1, 0, 3, &width, &height, &master);

if (!width) {
PHALCON_INIT_VAR(width);
} else {
PHALCON_SEPARATE_PARAM(width);
}

if (!height) {
PHALCON_INIT_VAR(height);
} else {
PHALCON_SEPARATE_PARAM(height);
}

if (!master) {
PHALCON_INIT_VAR(master);
ZVAL_LONG(master, 4);
} else {
PHALCON_SEPARATE_PARAM(master);
}

PHALCON_OBS_VAR(image_width);
phalcon_read_property_this(&image_width, this_ptr, SL("_width"), PH_NOISY_CC);

PHALCON_OBS_VAR(image_height);
phalcon_read_property_this(&image_height, this_ptr, SL("_height"), PH_NOISY_CC);

tmp_image_width = phalcon_get_intval(image_width);
tmp_image_height = phalcon_get_intval(image_height);

if (Z_TYPE_P(master) != IS_LONG) {
convert_to_long(master);
}

if (Z_LVAL_P(master) == 2 && Z_TYPE_P(width) == IS_LONG) {
ZVAL_LONG(master, 4);
} else if (Z_LVAL_P(master) == 3 && Z_TYPE_P(height) == IS_LONG) {
ZVAL_LONG(master, 4);
}
if (phalcon_get_intval(master) == 7) {
if (!width || !height) {
PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "width and height parameter must be input");
return;
}

if (Z_TYPE_P(width) != IS_LONG) {
if (Z_LVAL_P(master) == 1) {
tmp_width = tmp_image_width;
} else {
ZVAL_LONG(master, 3);
if (Z_TYPE_P(width) != IS_LONG) {
convert_to_long(width);
}

if (Z_TYPE_P(height) != IS_LONG) {
convert_to_long(height);
}
} else {
tmp_width = Z_LVAL_P(width);
}
if (!width) {
PHALCON_INIT_VAR(width);
} else {
PHALCON_SEPARATE_PARAM(width);
}

if (Z_TYPE_P(height) != IS_LONG) {
if (Z_LVAL_P(master) == 1) {
tmp_height = tmp_image_height;
if (!height) {
PHALCON_INIT_VAR(height);
} else {
ZVAL_LONG(master, 2);
PHALCON_SEPARATE_PARAM(height);
}
} else {
tmp_height = Z_LVAL_P(height);
}

switch (Z_LVAL_P(master)) {
case 4: // AUTO
{
if ( (tmp_image_width / tmp_width) > (tmp_image_height / tmp_height)) {
ZVAL_LONG(master, 2);
PHALCON_OBS_VAR(image_width);
phalcon_read_property_this(&image_width, this_ptr, SL("_width"), PH_NOISY_CC);

PHALCON_OBS_VAR(image_height);
phalcon_read_property_this(&image_height, this_ptr, SL("_height"), PH_NOISY_CC);

tmp_image_width = phalcon_get_intval(image_width);
tmp_image_height = phalcon_get_intval(image_height);

if (Z_LVAL_P(master) == 2 && Z_TYPE_P(width) == IS_LONG) {
ZVAL_LONG(master, 4);
} else if (Z_LVAL_P(master) == 3 && Z_TYPE_P(height) == IS_LONG) {
ZVAL_LONG(master, 4);
}

if (Z_TYPE_P(width) != IS_LONG) {
if (Z_LVAL_P(master) == 1) {
tmp_width = tmp_image_width;
} else {
ZVAL_LONG(master, 3);
}
break;
} else {
tmp_width = Z_LVAL_P(width);
}
case 5: // INVERSE
{
if ( (tmp_image_width / tmp_width) > (tmp_image_height / tmp_height)) {
ZVAL_LONG(master, 3);

if (Z_TYPE_P(height) != IS_LONG) {
if (Z_LVAL_P(master) == 1) {
tmp_height = tmp_image_height;
} else {
ZVAL_LONG(master, 2);
}
break;
} else {
tmp_height = Z_LVAL_P(height);
}

}

switch (Z_LVAL_P(master)) {
case 2: // WIDTH
{
tmp_height = (int)((tmp_image_height * tmp_width / tmp_image_width) + 0.5);
break;
}
case 3: // HEIGHT
{
tmp_width = (int)((tmp_image_width * tmp_height / tmp_image_height) + 0.5);
break;
switch (phalcon_get_intval(master)) {
case 4: // AUTO
{
if ( (tmp_image_width / tmp_width) > (tmp_image_height / tmp_height)) {
ZVAL_LONG(master, 2);
} else {
ZVAL_LONG(master, 3);
}
break;
}
case 5: // INVERSE
{
if ( (tmp_image_width / tmp_width) > (tmp_image_height / tmp_height)) {
ZVAL_LONG(master, 3);
} else {
ZVAL_LONG(master, 2);
}
break;
}

}
case 6: //PRECISE
{
if ((tmp_width / tmp_height) > (tmp_image_width / tmp_image_height)) {

switch (phalcon_get_intval(master)) {
case 2: // WIDTH
{
tmp_height = (int)((tmp_image_height * tmp_width / tmp_image_width) + 0.5);
} else {
break;
}
case 3: // HEIGHT
{
tmp_width = (int)((tmp_image_width * tmp_height / tmp_image_height) + 0.5);
break;
}
break;
case 6: //PRECISE
{
if ((tmp_width / tmp_height) > (tmp_image_width / tmp_image_height)) {
tmp_height = (int)((tmp_image_height * tmp_width / tmp_image_width) + 0.5);
} else {
tmp_width = (int)((tmp_image_width * tmp_height / tmp_image_height) + 0.5);
}
break;
}

}

if (tmp_width <= 0) {
tmp_width = 1;
}

}

if (tmp_width <= 0) {
tmp_width = 1;
}

if (tmp_height <= 0) {
tmp_height = 1;
}
if (tmp_height <= 0) {
tmp_height = 1;
}

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

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

phalcon_call_method_p2_noret(this_ptr, "_resize", width, height);

Expand Down
8 changes: 2 additions & 6 deletions ext/image/adapter/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, check){

PHALCON_INIT_NVAR(gd_version);
if (zend_get_constant(SL("GD_VERSION"), gd_version TSRMLS_CC) == FAILURE) {

if (!gd_info) {
PHALCON_INIT_NVAR(gd_info);
phalcon_call_func(gd_info, "gd_info");
}
PHALCON_INIT_NVAR(gd_info);
phalcon_call_func(gd_info, "gd_info");

PHALCON_INIT_NVAR(pattern);
ZVAL_STRING(pattern, "#\\d+\\.\\d+(?:\\.\\d+)?#", 1);
Expand Down Expand Up @@ -553,7 +550,6 @@ PHP_METHOD(Phalcon_Image_Adapter_GD, _sharpen) {
} else if (a < 1) {
a = 1;
}
b = a;

b = -18 + (a * 0.08);

Expand Down

0 comments on commit af2853d

Please sign in to comment.