Skip to content

Commit

Permalink
Merge pull request #1120 from dreamsxin/bug_image_1.3.0
Browse files Browse the repository at this point in the history
Bug image 1.3.0
  • Loading branch information
Phalcon committed Aug 20, 2013
2 parents 6fda7c1 + 0929db6 commit e815ee3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 120 deletions.
153 changes: 50 additions & 103 deletions ext/image/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ PHALCON_INIT_CLASS(Phalcon_Image_Adapter){
zend_declare_property_null(phalcon_image_adapter_ce, SL("_checked"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
zend_declare_property_null(phalcon_image_adapter_ce, SL("_file"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_image_adapter_ce, SL("_realpath"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_image_adapter_ce, SL("_imageinfo"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_image_adapter_ce, SL("_width"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_image_adapter_ce, SL("_height"), ZEND_ACC_PROTECTED TSRMLS_CC);
zend_declare_property_null(phalcon_image_adapter_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC);
Expand All @@ -75,64 +74,6 @@ PHALCON_INIT_CLASS(Phalcon_Image_Adapter){
return SUCCESS;
}

/**
* Phalcon\Image constructor
*/
PHP_METHOD(Phalcon_Image_Adapter, __construct){

zval *file, *realpath, *imageinfo, *exception_message;
zval *width, *height, *type, *mime;

PHALCON_MM_GROW();

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

if (Z_TYPE_P(file) != IS_STRING) {
PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "file parameter should be a string");
return;
}

phalcon_update_property_this(this_ptr, SL("_file"), file TSRMLS_CC);

PHALCON_INIT_VAR(realpath);
phalcon_realpath(realpath, file TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_realpath"), realpath TSRMLS_CC);

/**
* @todo getimagesize() is from GD, we need to create a method getImageSize()
* and implement it for every adapter
*/
PHALCON_INIT_VAR(imageinfo);
phalcon_call_func_p1(imageinfo, "getimagesize", realpath);

if (Z_TYPE_P(imageinfo) != IS_ARRAY) {
PHALCON_INIT_VAR(exception_message);
PHALCON_CONCAT_SVS(exception_message, "Can't open image file at '", realpath, "'");
PHALCON_THROW_EXCEPTION_ZVAL(phalcon_image_exception_ce, exception_message);
return;
}

if (phalcon_array_isset_long_fetch(&width, imageinfo, 0)) {
phalcon_update_property_this(this_ptr, SL("_width"), width TSRMLS_CC);
}

if (phalcon_array_isset_long_fetch(&height, imageinfo, 1)) {
phalcon_update_property_this(this_ptr, SL("_height"), height TSRMLS_CC);
}

if (phalcon_array_isset_long_fetch(&type, imageinfo, 2)) {
phalcon_update_property_this(this_ptr, SL("_type"), type TSRMLS_CC);
}

if (phalcon_array_isset_string_fetch(&mime, imageinfo, SS("mime"))) {
phalcon_update_property_this(this_ptr, SL("_mime"), mime TSRMLS_CC);
}

phalcon_update_property_this(this_ptr, SL("_imageinfo"), imageinfo TSRMLS_CC);

PHALCON_MM_RESTORE();
}

/**
* Returns the real path of the image file
*
Expand Down Expand Up @@ -424,6 +365,9 @@ PHP_METHOD(Phalcon_Image_Adapter, crop){
tmp_image_width = phalcon_get_intval(image_width);
tmp_image_height = phalcon_get_intval(image_height);

zend_print_zval_r(image_width, 0);
zend_print_zval_r(image_height, 0);

if (tmp_width > tmp_image_width) {
tmp_width = tmp_image_width;
}
Expand Down Expand Up @@ -761,7 +705,7 @@ PHP_METHOD(Phalcon_Image_Adapter, watermark){
PHP_METHOD(Phalcon_Image_Adapter, text){

zval *text, *offset_x = NULL, *offset_y = NULL, *opacity = NULL, *color = NULL, *size = NULL, *fontfile = NULL;
zval *tmp_color = NULL, *pattern, *replacement, *tmp = NULL, *r, *g, *b;
zval *tmp_color = NULL, *pattern, *replacement, *r, *g, *b;
int i;
char *c;

Expand Down Expand Up @@ -844,40 +788,40 @@ PHP_METHOD(Phalcon_Image_Adapter, text){
}

if (Z_STRLEN_P(tmp_color) == 3) {
PHALCON_INIT_VAR(pattern);
ZVAL_STRING(pattern, "#.#", 1);

PHALCON_INIT_VAR(replacement);
ZVAL_STRING(replacement, "$0$0", 1);

PHALCON_INIT_NVAR(tmp);
phalcon_call_func_p3(tmp, "preg_replace", pattern, replacement, tmp_color);

PHALCON_CPY_WRT(tmp_color, tmp);
/* Convert RGB to RRGGBB */
c = Z_STRVAL_P(tmp_color);
STR_REALLOC(c, 7);
c[6] = '\0';
c[5] = c[2];
c[4] = c[2];
c[3] = c[1];
c[2] = c[1];
c[1] = c[0];
}

ZVAL_STRING(tmp_color, c, 1);

if (Z_STRLEN_P(tmp_color) >= 6) {
PHALCON_INIT_NVAR(tmp);
phalcon_substr(tmp, tmp_color, 0, 2);
PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "color is not valid");
return;
}

PHALCON_INIT_VAR(r);
phalcon_call_func_p1(r, "hexdec", tmp);
zval tmp;
INIT_ZVAL(tmp);

PHALCON_INIT_NVAR(tmp);
phalcon_substr(tmp, tmp_color, 2, 2);
Z_TYPE(tmp) = IS_STRING;
ZVAL_STRINGL(&tmp, Z_STRVAL_P(tmp_color), 2, 0);

PHALCON_INIT_VAR(g);
phalcon_call_func_p1(g, "hexdec", tmp);
PHALCON_INIT_NVAR(r);
_php_math_basetozval(&tmp, 16, r);

PHALCON_INIT_NVAR(tmp);
phalcon_substr(tmp, tmp_color, 4, 2);
Z_STRVAL(tmp) += 2;
PHALCON_INIT_NVAR(g);
_php_math_basetozval(&tmp, 16, g);

PHALCON_INIT_VAR(b);
phalcon_call_func_p1(b, "hexdec", tmp);
} else {
PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "color is not valid");
return;
}
Z_STRVAL(tmp) += 2;
PHALCON_INIT_NVAR(b);
_php_math_basetozval(&tmp, 16, b);

PHALCON_CALL_METHOD(NULL, NULL, this_ptr, "_text", 0, 9, text, offset_x, offset_y, opacity, r, g, b, size, fontfile);

Expand Down Expand Up @@ -947,28 +891,31 @@ PHP_METHOD(Phalcon_Image_Adapter, background){
c[1] = c[0];
}

if (Z_STRLEN_P(tmp_color) >= 6) {
zval tmp;
INIT_ZVAL(tmp);

Z_TYPE(tmp) = IS_STRING;
ZVAL_STRINGL(&tmp, Z_STRVAL_P(tmp_color), 2, 0);

PHALCON_INIT_NVAR(r);
_php_math_basetozval(&tmp, 16, r);

Z_STRVAL(tmp) += 2;
PHALCON_INIT_NVAR(g);
_php_math_basetozval(&tmp, 16, g);
ZVAL_STRING(tmp_color, c, 1);

Z_STRVAL(tmp) += 2;
PHALCON_INIT_NVAR(b);
_php_math_basetozval(&tmp, 16, b);
} else {
if (Z_STRLEN_P(tmp_color) < 6) {
PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "color is not valid");
return;
}

zval tmp;
INIT_ZVAL(tmp);

Z_TYPE(tmp) = IS_STRING;
ZVAL_STRINGL(&tmp, Z_STRVAL_P(tmp_color), 2, 0);

PHALCON_INIT_NVAR(r);
_php_math_basetozval(&tmp, 16, r);

Z_STRVAL(tmp) += 2;
PHALCON_INIT_NVAR(g);
_php_math_basetozval(&tmp, 16, g);

Z_STRVAL(tmp) += 2;
PHALCON_INIT_NVAR(b);
_php_math_basetozval(&tmp, 16, b);


if (!opacity) {
PHALCON_INIT_NVAR(opacity);
ZVAL_LONG(opacity, 100);
Expand Down
6 changes: 0 additions & 6 deletions ext/image/adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern zend_class_entry *phalcon_image_adapter_ce;

PHALCON_INIT_CLASS(Phalcon_Image_Adapter);

PHP_METHOD(Phalcon_Image_Adapter, __construct);
PHP_METHOD(Phalcon_Image_Adapter, getRealPath);
PHP_METHOD(Phalcon_Image_Adapter, getWidth);
PHP_METHOD(Phalcon_Image_Adapter, getHeight);
Expand All @@ -51,10 +50,6 @@ PHP_METHOD(Phalcon_Image_Adapter, pixelate);
PHP_METHOD(Phalcon_Image_Adapter, save);
PHP_METHOD(Phalcon_Image_Adapter, render);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_image_adapter___construct, 0, 0, 1)
ZEND_ARG_INFO(0, file)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_image_adapter_resize, 0, 0, 0)
ZEND_ARG_INFO(0, width)
ZEND_ARG_INFO(0, height)
Expand Down Expand Up @@ -138,7 +133,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_image_adapter_render, 0, 0, 0)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_image_adapter_method_entry){
PHP_ME(Phalcon_Image_Adapter, __construct, arginfo_phalcon_image_adapter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(Phalcon_Image_Adapter, getRealPath, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Image_Adapter, getWidth, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Image_Adapter, getHeight, NULL, ZEND_ACC_PUBLIC)
Expand Down
45 changes: 34 additions & 11 deletions ext/image/adapter/imagick.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,50 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, __construct){
phalcon_call_static_noret("phalcon\\image\\adapter\\imagick", "check");
}

phalcon_update_property_this(this_ptr, SL("_file"), file TSRMLS_CC);

PHALCON_INIT_VAR(im);
object_init_ex(im, ce0);
if (phalcon_has_constructor(im TSRMLS_CC)) {
phalcon_call_method_noret(im, "__construct");
}

if (phalcon_file_exists(file TSRMLS_CC) != FAILURE) {
phalcon_call_parent_p1_noret(this_ptr, phalcon_image_adapter_imagick_ce, "__construct", file);

PHALCON_OBS_VAR(realpath);
phalcon_read_property_this(&realpath, this_ptr, SL("_realpath"), PH_NOISY_CC);
PHALCON_INIT_VAR(realpath);
phalcon_realpath(realpath, file TSRMLS_CC);
phalcon_update_property_this(this_ptr, SL("_realpath"), realpath TSRMLS_CC);

PHALCON_OBS_VAR(type);
phalcon_read_property_this(&type, this_ptr, SL("_type"), PH_NOISY_CC);
phalcon_call_method_p1_noret(im, "readImage", realpath);

if (width) {
PHALCON_SEPARATE_PARAM(width);
}

PHALCON_INIT_NVAR(width);
phalcon_call_method(width, im, "getImageWidth");
phalcon_update_property_this(this_ptr, SL("_width"), width TSRMLS_CC);

if (height) {
PHALCON_SEPARATE_PARAM(height);
}

PHALCON_INIT_NVAR(height);
phalcon_call_method(height, im, "getImageHeight");
phalcon_update_property_this(this_ptr, SL("_height"), height TSRMLS_CC);

PHALCON_INIT_NVAR(type);
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");

PHALCON_INIT_NVAR(mime);
PHALCON_CONCAT_SV(mime, "image/", format);

phalcon_update_property_this(this_ptr, SL("_mime"), mime TSRMLS_CC);

PHALCON_INIT_VAR(ret);
phalcon_call_method(ret, im, "getImageAlphaChannel");

Expand Down Expand Up @@ -889,11 +917,6 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _watermark) {
PHALCON_INIT_VAR(watermark);
phalcon_call_method(watermark, watermark_image, "getImage");

if (Z_TYPE_P(watermark) != IS_RESOURCE) {
PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "The watermark is not resource");
return;
}

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

PHALCON_INIT_VAR(channel);
Expand Down

0 comments on commit e815ee3

Please sign in to comment.