diff --git a/ext/image/adapter.c b/ext/image/adapter.c index cee4ba506d7..746c13d1c84 100644 --- a/ext/image/adapter.c +++ b/ext/image/adapter.c @@ -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); @@ -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); @@ -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) { @@ -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); } @@ -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); } @@ -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; } @@ -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) { @@ -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); } @@ -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); diff --git a/ext/image/adapter/gd.c b/ext/image/adapter/gd.c index a4ba5ef1fc7..e9535240a94 100644 --- a/ext/image/adapter/gd.c +++ b/ext/image/adapter/gd.c @@ -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); @@ -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(); @@ -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; @@ -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) { @@ -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(); } @@ -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); @@ -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(); } @@ -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); @@ -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); @@ -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); } @@ -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(); } diff --git a/ext/image/adapter/imagick.c b/ext/image/adapter/imagick.c index bf8f6d6c994..27c7db266ab 100644 --- a/ext/image/adapter/imagick.c +++ b/ext/image/adapter/imagick.c @@ -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"); @@ -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(); @@ -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(); } @@ -436,6 +444,8 @@ PHP_METHOD(Phalcon_Image_Adapter_Imagick, _rotate) { phalcon_fetch_params(1, 1, 0, °rees); + 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); @@ -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)) { @@ -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); @@ -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)) { @@ -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"); @@ -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 { @@ -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); @@ -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)) { @@ -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); @@ -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(); } diff --git a/unit-tests/ImageTest.php b/unit-tests/ImageTest.php index e0b9a20cfdb..114bf7a07eb 100644 --- a/unit-tests/ImageTest.php +++ b/unit-tests/ImageTest.php @@ -27,122 +27,135 @@ public function testGD() return; } - @unlink('unit-tests/assets/gd-new.jpg'); - @unlink('unit-tests/assets/gd-resize.jpg'); - @unlink('unit-tests/assets/gd-crop.jpg'); - @unlink('unit-tests/assets/gd-rotate.jpg'); - @unlink('unit-tests/assets/gd-flip.jpg'); - @unlink('unit-tests/assets/gd-sharpen.jpg'); - @unlink('unit-tests/assets/gd-reflection.jpg'); - @unlink('unit-tests/assets/gd-watermark.jpg'); - @unlink('unit-tests/assets/gd-background.jpg'); + @unlink('unit-tests/assets/production/gd-new.jpg'); + @unlink('unit-tests/assets/production/gd-resize.jpg'); + @unlink('unit-tests/assets/production/gd-crop.jpg'); + @unlink('unit-tests/assets/production/gd-rotate.jpg'); + @unlink('unit-tests/assets/production/gd-flip.jpg'); + @unlink('unit-tests/assets/production/gd-sharpen.jpg'); + @unlink('unit-tests/assets/production/gd-reflection.jpg'); + @unlink('unit-tests/assets/production/gd-watermark.jpg'); + @unlink('unit-tests/assets/production/gd-mask.jpg'); + @unlink('unit-tests/assets/production/gd-background.jpg'); - try { + // Create new image + $image = new Phalcon\Image\Adapter\GD('unit-tests/assets/production/gd-new.jpg', 100, 100); + $image->save(); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-new.jpg')); - // Create new image - $image = new Phalcon\Image\Adapter\GD('unit-tests/assets/gd-new.jpg', 100, 100); - $image->save(); - $this->assertTrue(file_exists('unit-tests/assets/production/new.jpg')); + $image = new Phalcon\Image\Adapter\GD('unit-tests/assets/phalconphp.jpg'); - $image = new Phalcon\Image\Adapter\GD('unit-tests/assets/phalconphp.jpg'); + // Resize to 200 pixels on the shortest side + $image->resize(200, 200)->save('unit-tests/assets/production/gd-resize.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-resize.jpg')); - // Resize to 200 pixels on the shortest side - $image->resize(200, 200)->save('unit-tests/assets/production/gd-resize.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/gd-resize.jpg')); + $tmp = imagecreatefromjpeg('unit-tests/assets/production/gd-resize.jpg'); + $width = imagesx($tmp); + $height = imagesy($tmp); + $this->assertTrue($width <= 200); + $this->assertTrue($height <= 200); - $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); + $this->assertTrue($image->getWidth() <= 200); + $this->assertTrue($image->getHeight() <= 200); - // Resize to 200x200 pixels, keeping aspect ratio - //$image->resize(200, 200, Phalcon\Image::INVERSE); + // Resize to 200x200 pixels, keeping aspect ratio + //$image->resize(200, 200, Phalcon\Image::INVERSE); - // Resize to 500 pixel width, keeping aspect ratio - //$image->resize(500, NULL); + // Resize to 500 pixel width, keeping aspect ratio + //$image->resize(500, NULL); - // Resize to 500 pixel height, keeping aspect ratio - //$image->resize(NULL, 500); + // Resize to 500 pixel height, keeping aspect ratio + //$image->resize(NULL, 500); - // Resize to 200x500 pixels, ignoring aspect ratio - //$image->resize(200, 500, Phalcon\Image::NONE); + // Resize to 200x500 pixels, ignoring aspect ratio + //$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')); + // 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); + $tmp = imagecreatefromjpeg('unit-tests/assets/production/gd-crop.jpg'); + $width = imagesx($tmp); + $height = imagesy($tmp); + $this->assertEquals($width, 200); + $this->assertEquals($height, 200); + $this->assertTrue($image->getWidth() == 200); + $this->assertTrue($image->getHeight() == 200); - // Rotate 45 degrees clockwise - $image->rotate(45)->save('unit-tests/assets/production/gd-rotate.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/gd-rotate.jpg')); - // Rotate 90% counter-clockwise - //$image->rotate(-90); + // Rotate 45 degrees clockwise + $image->rotate(45)->save('unit-tests/assets/production/gd-rotate.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-rotate.jpg')); - // Flip the image from top to bottom - $image->flip(Phalcon\Image::HORIZONTAL)->save('unit-tests/assets/production/gd-flip.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/gd-flip.jpg')); + $this->assertTrue($image->getWidth() > 200); + $this->assertTrue($image->getHeight() > 200); - // Flip the image from left to right - //$image->flip(Phalcon\Image::VERTICAL); + // Rotate 90% counter-clockwise + //$image->rotate(-90); - // Sharpen the image by 20% - $image->sharpen(20)->save('unit-tests/assets/production/gd-sharpen.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/gd-sharpen.jpg')); + // Flip the image from top to bottom + $image->flip(Phalcon\Image::HORIZONTAL)->save('unit-tests/assets/production/gd-flip.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-flip.jpg')); - // Create a 50 pixel reflection that fades from 0-100% opacity - $image->reflection(50)->save('unit-tests/assets/production/gd-reflection.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/gd-reflection.jpg')); + // Flip the image from left to right + //$image->flip(Phalcon\Image::VERTICAL); - // Create a 50 pixel reflection that fades from 100-0% opacity - //$image->reflection(50, 100, TRUE)->save('reflection.jpg'); + // Sharpen the image by 20% + $image->sharpen(20)->save('unit-tests/assets/production/gd-sharpen.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-sharpen.jpg')); - // Create a 50 pixel reflection that fades from 0-60% opacity - //$image->reflection(50, 60, TRUE); + // Create a 50 pixel reflection that fades from 0-100% opacity + $image->reflection(50)->save('unit-tests/assets/production/gd-reflection.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-reflection.jpg')); - // Add a watermark to the bottom right of the image - $mark = new Phalcon\Image\Adapter\GD('unit-tests/assets/logo.png'); - $image->watermark($mark, TRUE, TRUE)->save('unit-tests/assets/production/gd-watermark.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/gd-watermark.jpg')); + // Create a 50 pixel reflection that fades from 100-0% opacity + //$image->reflection(50, 100, TRUE)->save('reflection.jpg'); - // Add a text to the bottom right of the image - $image->text('hello', TRUE, TRUE); + // Create a 50 pixel reflection that fades from 0-60% opacity + //$image->reflection(50, 60, TRUE); - // Set font size - // $image->text('hello', TRUE, TRUE, NULL, NULL, 12); + // Add a watermark to the bottom right of the image + $mark = new Phalcon\Image\Adapter\GD('unit-tests/assets/logo.png'); + $image->watermark($mark, TRUE, TRUE)->save('unit-tests/assets/production/gd-watermark.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-watermark.jpg')); - // Set font - // $image->text('hello', TRUE, TRUE, NULL, NULL, 12, /usr/share/fonts/truetype/wqy/wqy-microhei.ttc); + // Mask image + $mask = new Phalcon\Image\Adapter\GD('unit-tests/assets/logo.png'); + $image->mask($mask)->save('unit-tests/assets/production/gd-mask.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-mask.jpg')); - // Add a text to the center of the image - //$image->text('hello'); + // Add a text to the bottom right of the image + $image->text('hello', TRUE, TRUE); - // Make the image background black - $mark->background('#000')->save('unit-tests/assets/production/gd-background.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/gd-background.jpg')); + // Set font size + // $image->text('hello', TRUE, TRUE, NULL, NULL, 12); - // Make the image background black with 50% opacity - //$image->background('#000', 50); + // Set font + // $image->text('hello', TRUE, TRUE, NULL, NULL, 12, /usr/share/fonts/truetype/wqy/wqy-microhei.ttc); - // Save the image as a PNG - //$image->save('saved/gd.png'); + // Add a text to the center of the image + //$image->text('hello'); - // Overwrite the original image - //$image->save(); + // Make the image background black + $mark->background('#000')->save('unit-tests/assets/production/gd-background.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/gd-background.jpg')); - // Render the image at 50% quality - //$data = $image->render(NULL, 50); - - // Render the image as a PNG - //$data = $image->render('png'); - } catch (Exception $e) { - } + // Make the image background black with 50% opacity + //$image->background('#000', 50); + + // Save the image as a PNG + //$image->save('saved/gd.png'); + + // Overwrite the original image + //$image->save(); + + // Render the image at 50% quality + //$data = $image->render(NULL, 50); + + // Render the image as a PNG + //$data = $image->render('png'); } public function testImagick() @@ -160,108 +173,122 @@ public function testImagick() @unlink('unit-tests/assets/production/imagick-sharpen.jpg'); @unlink('unit-tests/assets/production/imagick-reflection.jpg'); @unlink('unit-tests/assets/production/imagick-watermark.jpg'); + @unlink('unit-tests/assets/production/imagick-mask.jpg'); @unlink('unit-tests/assets/production/imagick-background.jpg'); - try { - // Create new image - $image = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/imagick-new.jpg', 100, 100); - $image->save(); - $this->assertTrue(file_exists('unit-tests/assets/production/new.jpg')); + // Create new image + $image = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/production/imagick-new.jpg', 100, 100); + $image->save(); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-new.jpg')); - $image = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/phalconphp.jpg'); + $image = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/phalconphp.jpg'); - // Resize to 200 pixels on the shortest side - $image->resize(200, 200)->save('unit-tests/assets/production/imagick-resize.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-resize.jpg')); + // Resize to 200 pixels on the shortest side + $image->resize(200, 200)->save('unit-tests/assets/production/imagick-resize.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-resize.jpg')); + $this->assertTrue($image->getWidth() <= 200); + $this->assertTrue($image->getHeight() <= 200); - // Resize to 200x200 pixels, keeping aspect ratio - //$image->resize(200, 200, Phalcon\Image::INVERSE); + // Resize to 200x200 pixels, keeping aspect ratio + //$image->resize(200, 200, Phalcon\Image::INVERSE); - // Resize to 500 pixel width, keeping aspect ratio - //$image->resize(500, NULL); + // Resize to 500 pixel width, keeping aspect ratio + //$image->resize(500, NULL); - // Resize to 500 pixel height, keeping aspect ratio - //$image->resize(NULL, 500); + // Resize to 500 pixel height, keeping aspect ratio + //$image->resize(NULL, 500); - // Resize to 200x500 pixels, ignoring aspect ratio - //$image->resize(200, 500, Phalcon\Image::NONE); + // Resize to 200x500 pixels, ignoring aspect ratio + //$image->resize(200, 500, Phalcon\Image::NONE); - // The images using liquid rescaling resize to 200x200 - $image->liquidRescale(200, 200)->save('unit-tests/assets/production/imagick-liquidRescale.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-liquidRescale.jpg')); + // The images using liquid rescaling resize to 200x200 + $image->liquidRescale(200, 200)->save('unit-tests/assets/production/imagick-liquidRescale.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-liquidRescale.jpg')); + $this->assertTrue($image->getWidth() == 200); + $this->assertTrue($image->getHeight() == 200); - // The images using liquid rescaling resize to 500x500 - //$image->liquidRescale(500, 500, 3, 25); + // The images using liquid rescaling resize to 500x500 + //$image->liquidRescale(500, 500, 3, 25); - // Crop the image to 200x200 pixels, from the center - $image->crop(200, 200)->save('unit-tests/assets/production/imagick-crop.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-crop.jpg')); + // Crop the image to 200x200 pixels, from the center + $image = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/phalconphp.jpg'); + $image->crop(200, 200)->save('unit-tests/assets/production/imagick-crop.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-crop.jpg')); - // Rotate 45 degrees clockwise - $image->rotate(45)->save('unit-tests/assets/production/imagick-rotate.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-rotate.jpg')); + $this->assertTrue($image->getWidth() == 200); + $this->assertTrue($image->getHeight() == 200); - // Rotate 90% counter-clockwise - //$image->rotate(-90); + // Rotate 45 degrees clockwise + $image->rotate(45)->save('unit-tests/assets/production/imagick-rotate.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-rotate.jpg')); - // Flip the image from top to bottom - $image->flip(Phalcon\Image::HORIZONTAL)->save('unit-tests/assets/production/imagick-flip.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-flip.jpg')); + $this->assertTrue($image->getWidth() > 200); + $this->assertTrue($image->getHeight() > 200); - // Flip the image from left to right - //$image->flip(Phalcon\Image::VERTICAL); + // Rotate 90% counter-clockwise + //$image->rotate(-90); - // Sharpen the image by 20% - $image->sharpen(20)->save('unit-tests/assets/production/imagick-sharpen.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-sharpen.jpg')); + // Flip the image from top to bottom + $image->flip(Phalcon\Image::HORIZONTAL)->save('unit-tests/assets/production/imagick-flip.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-flip.jpg')); - // Create a 50 pixel reflection that fades from 0-100% opacity - $image->reflection(50)->save('unit-tests/assets/production/imagick-reflection.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-reflection.jpg')); + // Flip the image from left to right + //$image->flip(Phalcon\Image::VERTICAL); - // Create a 50 pixel reflection that fades from 100-0% opacity - //$image->reflection(50, 100, TRUE)->save('reflection.jpg'); + // Sharpen the image by 20% + $image->sharpen(20)->save('unit-tests/assets/production/imagick-sharpen.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-sharpen.jpg')); - // Create a 50 pixel reflection that fades from 0-60% opacity - //$image->reflection(50, 60, TRUE); + // Create a 50 pixel reflection that fades from 0-100% opacity + $image->reflection(50)->save('unit-tests/assets/production/imagick-reflection.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-reflection.jpg')); - // Add a watermark to the bottom right of the image - $mark = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/logo.png'); - $image->watermark($mark, TRUE, TRUE)->save('unit-tests/assets/production/imagick-watermark.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-watermark.jpg')); + // Create a 50 pixel reflection that fades from 100-0% opacity + //$image->reflection(50, 100, TRUE)->save('reflection.jpg'); - // Add a text to the bottom right of the image - $image->text('hello', TRUE, TRUE); + // Create a 50 pixel reflection that fades from 0-60% opacity + //$image->reflection(50, 60, TRUE); - // Set font size - //$image->text('hello', TRUE, TRUE, NULL, NULL, 12); + // Add a watermark to the bottom right of the image + $mark = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/logo.png'); + $image->watermark($mark, TRUE, TRUE)->save('unit-tests/assets/production/imagick-watermark.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-watermark.jpg')); - // Set font - //$image->text('hello', TRUE, TRUE, NULL, NULL, 12, /usr/share/fonts/truetype/wqy/wqy-microhei.ttc); + // Mask image + $mask = new Phalcon\Image\Adapter\Imagick('unit-tests/assets/logo.png'); + $image->mask($mask)->save('unit-tests/assets/production/imagick-mask.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-mask.jpg')); - // Add a text to the center of the image - //$image->text('hello'); + // Add a text to the bottom right of the image + $image->text('hello', TRUE, TRUE); - // Make the image background black - $mark->background('#000')->save('unit-tests/assets/production/imagick-background.jpg'); - $this->assertTrue(file_exists('unit-tests/assets/production/imagick-background.jpg')); + // Set font size + //$image->text('hello', TRUE, TRUE, NULL, NULL, 12); - // Make the image background black with 50% opacity - //$image->background('#000', 50); + // Set font + //$image->text('hello', TRUE, TRUE, NULL, NULL, 12, /usr/share/fonts/truetype/wqy/wqy-microhei.ttc); - // Save the image as a PNG - //$image->save('saved/gd.png'); + // Add a text to the center of the image + //$image->text('hello'); - // Overwrite the original image - //$image->save(); + // Make the image background black + $mark->background('#000')->save('unit-tests/assets/production/imagick-background.jpg'); + $this->assertTrue(file_exists('unit-tests/assets/production/imagick-background.jpg')); - // Render the image at 50% quality - //$data = $image->render(NULL, 50); - - // Render the image as a PNG - //$data = $image->render('png'); - } catch (Exception $e) { - } + // Make the image background black with 50% opacity + //$image->background('#000', 50); + + // Save the image as a PNG + //$image->save('saved/gd.png'); + + // Overwrite the original image + //$image->save(); + + // Render the image at 50% quality + //$data = $image->render(NULL, 50); + + // Render the image as a PNG + //$data = $image->render('png'); } } \ No newline at end of file