/** * This method scales the images using liquid rescaling method. Only support Imagick * * @param int $width new width * @param int $height new height * @param int $delta_x How much the seam can traverse on x-axis. Passing 0 causes the seams to be straight. * @param int $rigidity Introduces a bias for non-straight seams. This parameter is typically 0. * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, liquidRescale) { zval **width, **height, **delta_x = NULL, **rigidity = NULL; phalcon_fetch_params_ex(2, 2, &width, &height, &delta_x, &rigidity); PHALCON_ENSURE_IS_LONG(width); PHALCON_ENSURE_IS_LONG(height); PHALCON_MM_GROW(); if (!delta_x) { delta_x = &PHALCON_GLOBAL(z_zero); } else { PHALCON_ENSURE_IS_LONG(delta_x); } if (!rigidity) { rigidity = &PHALCON_GLOBAL(z_zero); } else { PHALCON_ENSURE_IS_LONG(rigidity); } PHALCON_CALL_METHOD(NULL, this_ptr, "_liquidrescale", *width, *height, *delta_x, *rigidity); RETURN_THIS(); }
/** * Rotate the image by a given amount. * * @param int $degrees degrees to rotate: -360-360 * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, rotate) { zval **degrees, *d; long tmp_degrees; phalcon_fetch_params_ex(1, 0, °rees); PHALCON_ENSURE_IS_LONG(degrees); PHALCON_MM_GROW(); tmp_degrees = Z_LVAL_PP(degrees); if (tmp_degrees > 180) { tmp_degrees %= 360; if (tmp_degrees > 180) { tmp_degrees -= 360; }; } else if (tmp_degrees < -180) { do { tmp_degrees += 360; } while (tmp_degrees < -180); } PHALCON_ALLOC_GHOST_ZVAL(d); ZVAL_LONG(d, tmp_degrees); PHALCON_CALL_METHOD(NULL, this_ptr, "_rotate", d); RETURN_THIS(); }
/** * Decrement of a given key, by number $value * * @param string $keyName * @param long $value * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Apc, decrement){ zval *key_name, *value = NULL, prefix = {}, prefixed_key = {}, cached_content = {}; phalcon_fetch_params(0, 1, 1, &key_name, &value); if (!value || Z_TYPE_P(value) == IS_NULL) { value = &PHALCON_GLOBAL(z_one); } else { PHALCON_ENSURE_IS_LONG(value); } phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY); PHALCON_CONCAT_SVV(&prefixed_key, "_PHCA", &prefix, key_name); phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key); if (SUCCESS == phalcon_function_exists_ex(SL("apc_dec"))) { PHALCON_RETURN_CALL_FUNCTIONW("apc_dec", &prefixed_key, value); } else { PHALCON_CALL_FUNCTIONW(&cached_content, "apc_fetch", &prefixed_key); if (Z_TYPE(cached_content) == IS_LONG) { phalcon_sub_function(return_value, &cached_content, value); PHALCON_CALL_METHODW(NULL, getThis(), "save", key_name, return_value); } else { RETURN_FALSE; } } }
/** * Changes a parameter in the definition without resolve the service * * @param long $position * @param array $parameter * @return Phalcon\DI\Service */ PHP_METHOD(Phalcon_DI_Service, setParameter){ zval *position, *parameter, definition = {}, arguments = {}; phalcon_fetch_params(0, 2, 0, &position, ¶meter); PHALCON_ENSURE_IS_LONG(position); phalcon_return_property(&definition, getThis(), SL("_definition")); if (unlikely(Z_TYPE(definition) != IS_ARRAY)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "Definition must be an array to update its parameters"); return; } if (unlikely(Z_TYPE_P(parameter) != IS_ARRAY)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "The parameter must be an array"); return; } /* Update the parameter */ if (phalcon_array_isset_fetch_str(&arguments, &definition, SL("arguments"))) { phalcon_array_update_zval(&arguments, position, parameter, PH_COPY); } else { array_init_size(&arguments, 1); phalcon_array_update_zval(&arguments, position, parameter, PH_COPY); } phalcon_array_update_str(&definition, SL("arguments"), &arguments, PH_COPY); phalcon_update_property_zval(getThis(), SL("_definition"), &definition); RETURN_THISW(); }
/** * Sets the HTML quoting type for htmlspecialchars * *<code> * $escaper->setHtmlQuoteType(ENT_XHTML); *</code> * * @param int $quoteType */ PHP_METHOD(Phalcon_Escaper, setHtmlQuoteType){ zval **quote_type; phalcon_fetch_params_ex(1, 0, "e_type); PHALCON_ENSURE_IS_LONG(quote_type); phalcon_update_property_this(this_ptr, SL("_htmlQuoteType"), *quote_type TSRMLS_CC); }
/** * Sets the HTML quoting type for htmlspecialchars * *<code> * $escaper->setHtmlQuoteType(ENT_XHTML); *</code> * * @param int $quoteType */ PHP_METHOD(Phalcon_Escaper, setHtmlQuoteType){ zval *quote_type; phalcon_fetch_params(0, 1, 0, "e_type); PHALCON_ENSURE_IS_LONG(quote_type); phalcon_update_property_this(getThis(), SL("_htmlQuoteType"), quote_type); }
/** * Sets the default working factor for bcrypts password's salts * * @param int $workFactor */ PHP_METHOD(Phalcon_Security, setWorkFactor){ zval **work_factor; phalcon_fetch_params_ex(1, 0, &work_factor); PHALCON_ENSURE_IS_LONG(work_factor); phalcon_update_property_this(this_ptr, SL("_workFactor"), *work_factor TSRMLS_CC); }
/** * Set current rows limit * * @param int $limit * * @return Phalcon\Paginator\Adapter\Sql $this Fluent interface */ PHP_METHOD(Phalcon_Paginator_Adapter_Sql, setLimit){ zval *current_limit; phalcon_fetch_params(0, 1, 0, ¤t_limit); PHALCON_ENSURE_IS_LONG(current_limit); phalcon_update_property_zval(getThis(), SL("_limitRows"), current_limit); RETURN_THISW(); }
/** * Sets the number of lines deplayed after the error line * * @brief \Phalcon\Debug \Phalcon\Debug::setLinesAfterContext(int $lines) * @param int $lines * @return \Phalcon\Debug */ PHP_METHOD(Phalcon_Debug, setLinesAfterContext) { zval **lines; phalcon_fetch_params_ex(1, 0, &lines); PHALCON_ENSURE_IS_LONG(lines); phalcon_update_property_this(getThis(), SL("_afterContext"), *lines TSRMLS_CC); RETURN_THISW(); }
/** * Set the current page number * * @param int $page */ PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, setCurrentPage){ zval *current_page; phalcon_fetch_params(0, 1, 0, ¤t_page); PHALCON_ENSURE_IS_LONG(current_page); phalcon_update_property_this(getThis(), SL("_page"), current_page); RETURN_THISW(); }
/** * @brief Phalcon\CryptInterface Phalcon\Crypt::setPadding(int $scheme) * * @param int scheme Padding scheme * @return Phalcon\CryptInterface */ PHP_METHOD(Phalcon_Crypt, setPadding) { zval **scheme; phalcon_fetch_params_ex(1, 0, &scheme); PHALCON_ENSURE_IS_LONG(scheme); phalcon_update_property_this(this_ptr, SL("_padding"), *scheme TSRMLS_CC); RETURN_THISW(); }
/** * Sets the options * * @param int $options * @return Phalcon\CryptInterface */ PHP_METHOD(Phalcon_Crypt, setOptions) { zval *options; phalcon_fetch_params(0, 1, 0, &options); PHALCON_ENSURE_IS_LONG(options); phalcon_update_property_zval(getThis(), SL("_options"), options); RETURN_THISW(); }
/** * Parses a raw doc block returning the annotations found * * @param string $docBlock * @param string $file * @param int $line * @return array */ PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock) { zval **doc_block, **file = NULL, **line = NULL; phalcon_fetch_params_ex(3, 0, &doc_block, &file, &line); PHALCON_ENSURE_IS_STRING(doc_block); PHALCON_ENSURE_IS_STRING(file); PHALCON_ENSURE_IS_LONG(line); RETURN_ON_FAILURE(phannot_parse_annotations(return_value, Z_STRVAL_PP(doc_block), Z_STRLEN_PP(doc_block), Z_STRVAL_PP(file), Z_LVAL_PP(line) TSRMLS_CC)); }
/** * Checks a plain text password and its hash version to check if the password matches * * @param string $password * @param string $passwordHash * @param int $maxPasswordLength * @return boolean */ PHP_METHOD(Phalcon_Security, checkHash){ zval **password, **password_hash, **max_pass_length = NULL, *hash; zval* params[2]; int check = 0; phalcon_fetch_params_ex(2, 1, &password, &password_hash, &max_pass_length); PHALCON_ENSURE_IS_STRING(password); if (max_pass_length) { PHALCON_ENSURE_IS_LONG(max_pass_length); if (Z_LVAL_PP(max_pass_length) > 0 && Z_STRLEN_PP(password) > Z_LVAL_PP(max_pass_length)) { RETURN_FALSE; } } params[0] = *password; params[1] = *password_hash; ALLOC_INIT_ZVAL(hash); phalcon_call_func_params_w(hash, SL("crypt"), 2, params TSRMLS_CC); if (UNEXPECTED(EG(exception) != NULL)) { zval_ptr_dtor(&hash); RETURN_NULL(); } if (UNEXPECTED(Z_TYPE_P(hash) != IS_STRING)) { convert_to_string(hash); } if (Z_STRLEN_P(hash) == Z_STRLEN_PP(password_hash)) { int n = Z_STRLEN_P(hash); char *h1 = Z_STRVAL_P(hash); char *h2 = Z_STRVAL_PP(password_hash); while (n) { check |= ((unsigned int)*h1) ^ ((unsigned int)*h2); ++h1; ++h2; --n; } zval_ptr_dtor(&hash); RETURN_BOOL(check == 0); } zval_ptr_dtor(&hash); RETURN_FALSE; }
/** * Sets a number of bytes to be generated by the openssl pseudo random generator * * @param string $randomBytes */ PHP_METHOD(Phalcon_Security, setRandomBytes){ zval **random_bytes; phalcon_fetch_params_ex(1, 0, &random_bytes); PHALCON_ENSURE_IS_LONG(random_bytes); if (PHALCON_LT_LONG(*random_bytes, 16)) { PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "At least 16 bytes are needed to produce a correct salt"); return; } phalcon_update_property_this(this_ptr, SL("_numberBytes"), *random_bytes TSRMLS_CC); }
/** * Flip the image along the horizontal or vertical axis. * * @param $int $direction direction: Image::HORIZONTAL, Image::VERTICAL * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, flip) { zval **direction, *dir; phalcon_fetch_params_ex(1, 0, &direction); PHALCON_ENSURE_IS_LONG(direction); PHALCON_MM_GROW(); PHALCON_ALLOC_GHOST_ZVAL(dir); ZVAL_LONG(dir, (Z_LVAL_PP(direction) != 11) ? 12 : 11); PHALCON_CALL_METHOD(NULL, this_ptr, "_flip", dir); RETURN_THIS(); }
/** * Add a reflection to an image. The most opaque part of the reflection * will be equal to the opacity setting and fade out to full transparent. * Alpha transparency is preserved. * * @param int $height reflection height * @param int $opacity reflection opacity: 0-100 * @param boolean $fade_in TRUE to fade in, FALSE to fade out * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, reflection) { zval **h = NULL, **op = NULL, **fade_in = NULL; zval *image_height, *height = NULL, *opacity = NULL; long tmp_image_height; phalcon_fetch_params_ex(0, 3, &h, &op, &fade_in); PHALCON_MM_GROW(); image_height = phalcon_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY TSRMLS_CC); tmp_image_height = phalcon_get_intval(image_height); if (!h || Z_TYPE_PP(h) != IS_LONG || Z_LVAL_PP(h) > tmp_image_height) { PHALCON_INIT_VAR(height); ZVAL_LONG(height, tmp_image_height); } else { PHALCON_CPY_WRT_CTOR(height, *h); } if (!op) { PHALCON_INIT_VAR(opacity); ZVAL_LONG(opacity, 100); } else { PHALCON_ENSURE_IS_LONG(op); if (Z_LVAL_PP(op) > 100) { PHALCON_INIT_VAR(opacity); ZVAL_LONG(opacity, 100); } else if (Z_LVAL_PP(op) < 0) { PHALCON_INIT_VAR(opacity); ZVAL_LONG(opacity, 0); } else { PHALCON_CPY_WRT_CTOR(opacity, *op); } } if (!fade_in) { fade_in = &PHALCON_GLOBAL(z_false); } PHALCON_CALL_METHOD(NULL, this_ptr, "_reflection", height, opacity, *fade_in); RETURN_THIS(); }
/** * Reads meta-data for certain model using a MODEL_* constant * *<code> * print_r($metaData->writeColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP, array('leName' => 'name'))); *</code> * * @param Phalcon\Mvc\ModelInterface $model * @param int $index * @return array */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaDataIndex){ zval **model, **index, *table = NULL, *schema = NULL, *class_name; zval *key, *meta_data = NULL, *meta_data_index, *attributes; phalcon_fetch_params_ex(2, 0, &model, &index); PHALCON_VERIFY_INTERFACE_EX(*model, phalcon_mvc_modelinterface_ce, phalcon_mvc_model_exception_ce, 0); PHALCON_ENSURE_IS_LONG(index); PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&table, *model, "getsource"); PHALCON_CALL_METHOD(&schema, *model, "getschema"); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, *model, 1 TSRMLS_CC); /** * Unique key for meta-data is created using class-name-schema-table */ PHALCON_INIT_VAR(key); PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table); PHALCON_OBS_VAR(meta_data); phalcon_read_property_this(&meta_data, this_ptr, SL("_metaData"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset(meta_data, key)) { PHALCON_CALL_METHOD(NULL, this_ptr, "_initialize", *model, key, table, schema); PHALCON_OBS_NVAR(meta_data); phalcon_read_property_this(&meta_data, this_ptr, SL("_metaData"), PH_NOISY TSRMLS_CC); } PHALCON_OBS_VAR(meta_data_index); phalcon_array_fetch(&meta_data_index, meta_data, key, PH_NOISY); PHALCON_OBS_VAR(attributes); phalcon_array_fetch(&attributes, meta_data_index, *index, PH_NOISY); RETURN_CTOR(attributes); }
/** * Returns the string meaning of a logger constant * * @param integer $type * @return string */ PHP_METHOD(Phalcon_Logger_Formatter, getTypeString){ static const char *lut[10] = { "EMERGENCY", "CRITICAL", "ALERT", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG", "CUSTOM", "SPECIAL" }; zval *type; int itype; phalcon_fetch_params(0, 1, 0, &type); PHALCON_ENSURE_IS_LONG(type); itype = Z_LVAL_P(type); if (itype >= 0 && itype < 10) { RETURN_STRING(lut[itype]); } RETURN_STRING("CUSTOM"); }
/** * Returns the string meaning of a logger constant * * @param integer $type * @return string */ PHP_METHOD(Phalcon_Logger_Formatter_Firephp, getTypeString) { static const char* lut[10] = { "ERROR", "ERROR", "WARN", "ERROR", "WARN", "INFO", "INFO", "LOG", "INFO", "LOG" }; zval **type; int itype; phalcon_fetch_params_ex(1, 0, &type); PHALCON_ENSURE_IS_LONG(type); itype = Z_LVAL_PP(type); if (itype > 0 && itype < 10) { RETURN_STRING(lut[itype], 1); } RETURN_STRING("CUSTOM", 1); }
/** * Returns a parameter in a specific position * * @param int $position * @return array */ PHP_METHOD(Phalcon_DI_Service, getParameter){ zval *position, definition = {}, arguments = {}; phalcon_fetch_params(0, 1, 0, &position); PHALCON_ENSURE_IS_LONG(position); phalcon_return_property(&definition, getThis(), SL("_definition")); if (Z_TYPE(definition) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "Definition must be an array to obtain its parameters"); return; } /* Update the parameter */ if ( !phalcon_array_isset_fetch_str(&arguments, &definition, SL("arguments")) || !phalcon_array_isset_fetch(return_value, &arguments, position, 0) ) { RETURN_NULL(); } }
/** * Reads column-map information for certain model using a MODEL_* constant * *<code> * print_r($metaData->readColumnMapIndex(new Robots(), MetaData::MODELS_REVERSE_COLUMN_MAP)); *</code> * * @param Phalcon\Mvc\ModelInterface $model * @param int $index */ PHP_METHOD(Phalcon_Mvc_Model_MetaData, readColumnMapIndex){ zval **model, **index, *key_name, *column_map = NULL, *null_value; zval *column_map_model, *attributes; phalcon_fetch_params_ex(2, 0, &model, &index); PHALCON_VERIFY_CLASS_EX(*model, phalcon_mvc_modelinterface_ce, phalcon_mvc_model_exception_ce, 0); PHALCON_ENSURE_IS_LONG(index); PHALCON_MM_GROW(); if (!PHALCON_GLOBAL(orm).column_renaming) { RETURN_MM(); } PHALCON_INIT_VAR(key_name); phalcon_get_class(key_name, *model, 1 TSRMLS_CC); PHALCON_OBS_VAR(column_map); phalcon_read_property_this(&column_map, this_ptr, SL("_columnMap"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset(column_map, key_name)) { null_value = PHALCON_GLOBAL(z_null); PHALCON_CALL_METHOD(NULL, this_ptr, "_initialize", *model, null_value, null_value, null_value); PHALCON_OBS_NVAR(column_map); phalcon_read_property_this(&column_map, this_ptr, SL("_columnMap"), PH_NOISY TSRMLS_CC); } PHALCON_OBS_VAR(column_map_model); phalcon_array_fetch(&column_map_model, column_map, key_name, PH_NOISY); PHALCON_OBS_VAR(attributes); phalcon_array_fetch(&attributes, column_map_model, *index, PH_NOISY); RETURN_CTOR(attributes); }
/** * Pixelate image * * @param int $amount amount to pixelate * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, pixelate) { zval **amount = NULL, *amt; phalcon_fetch_params_ex(0, 1, &amount); PHALCON_MM_GROW(); PHALCON_ALLOC_GHOST_ZVAL(amt); if (!amount || Z_TYPE_PP(amount) != IS_LONG) { ZVAL_LONG(amt, 10); } else { PHALCON_ENSURE_IS_LONG(amount); if (Z_LVAL_PP(amount) < 2) { ZVAL_LONG(amt, 2); } else { ZVAL_LONG(amt, Z_LVAL_PP(amount)); } } PHALCON_CALL_METHOD(NULL, this_ptr, "_pixelate", amt); RETURN_THIS(); }
/** * Add a text to an image with a specified opacity. * * @param string text * @param int $offset_x offset from the left, If less than 0 offset from the right, If true right the x offset * @param int $offset_y offset from the top, If less than 0 offset from the bottom, If true bottom the Y offset * @param int $opacity opacity of text: 1-100 * @param string $color hexadecimal color value * @param int $size font pointsize * @param string $fontfile font path * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, text) { zval **text, **ofs_x = NULL, **ofs_y = NULL, **op = NULL, **fontcolor = NULL, **fontsize = NULL, **fontfile = NULL; zval *offset_x = NULL, *offset_y = NULL, *opacity, *color, *size; zval *r, *g, *b; char *c; zval tmp; phalcon_fetch_params_ex(1, 6, &text, &ofs_x, &ofs_y, &op, &fontcolor, &fontsize, &fontfile); PHALCON_MM_GROW(); if (!ofs_x || Z_TYPE_PP(ofs_x) == IS_NULL) { PHALCON_INIT_VAR(offset_x); ZVAL_FALSE(offset_x); } else { PHALCON_CPY_WRT_CTOR(offset_x, *ofs_x); } if (!ofs_y || Z_TYPE_PP(ofs_y) == IS_NULL) { PHALCON_INIT_VAR(offset_y); ZVAL_FALSE(offset_y); } else { PHALCON_CPY_WRT_CTOR(offset_y, *ofs_y); } PHALCON_INIT_VAR(opacity); if (!op || Z_TYPE_PP(op) == IS_NULL) { ZVAL_LONG(opacity, 100); } else { PHALCON_ENSURE_IS_LONG(op); if (Z_LVAL_PP(op) < 1) { ZVAL_LONG(opacity, 1); } else if (Z_LVAL_PP(op) > 100) { ZVAL_LONG(opacity, 100); } else { ZVAL_LONG(opacity, Z_LVAL_PP(op)); } } PHALCON_INIT_VAR(color); if (!fontcolor || Z_TYPE_PP(fontcolor) == IS_NULL) { ZVAL_STRING(color, "000000", 1); } else { PHALCON_ENSURE_IS_STRING(fontcolor); if (Z_STRLEN_PP(fontcolor) > 1 && Z_STRVAL_PP(fontcolor)[0] == '#') { phalcon_substr(color, *fontcolor, 1, 0); } else { ZVAL_STRINGL(color, Z_STRVAL_PP(fontcolor), Z_STRLEN_PP(fontcolor), 1); } } PHALCON_INIT_VAR(size); if (!fontsize || Z_TYPE_PP(fontsize) == IS_NULL) { ZVAL_LONG(size, 12); } else { PHALCON_ENSURE_IS_LONG(fontsize); ZVAL_LONG(size, Z_LVAL_PP(fontsize)); } if (!fontfile) { fontfile = &PHALCON_GLOBAL(z_null); } if (Z_STRLEN_P(color) == 3) { /* Convert RGB to RRGGBB */ c = Z_STRVAL_P(color); assert(!IS_INTERNED(c)); 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(color, c, 0); } if (Z_STRLEN_P(color) < 6) { PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "color is not valid"); return; } INIT_ZVAL(tmp); Z_TYPE(tmp) = IS_STRING; ZVAL_STRINGL(&tmp, Z_STRVAL_P(color), 2, 0); PHALCON_INIT_VAR(r); _php_math_basetozval(&tmp, 16, r); Z_STRVAL(tmp) += 2; PHALCON_INIT_VAR(g); _php_math_basetozval(&tmp, 16, g); Z_STRVAL(tmp) += 2; PHALCON_INIT_VAR(b); _php_math_basetozval(&tmp, 16, b); PHALCON_CALL_METHOD(NULL, this_ptr, "_text", *text, offset_x, offset_y, opacity, r, g, b, size, *fontfile); RETURN_THIS(); }
/** * Add a watermark to an image with a specified opacity. Alpha transparency * will be preserved. * * @param Phalcon\Image\Adapter $watermark watermark Image instance * @param int $offset_x offset from the left, If less than 0 offset from the right, If true right the x offset * @param int $offset_y offset from the top, If less than 0 offset from the bottom, If true bottom the Y offset * @param int $opacity opacity of watermark: 1-100 * @return Phalcon\Image\AdapterInterface */ PHP_METHOD(Phalcon_Image_Adapter, watermark) { zval **watermark, **ofs_x = NULL, **ofs_y = NULL, **op = NULL; zval *offset_x, *offset_y, *opacity; zval *image_width, *image_height, *watermark_width, *watermark_height; long tmp_image_width, tmp_image_height, tmp_watermark_width, tmp_watermark_height, tmp_offset_x, tmp_offset_y; phalcon_fetch_params_ex(1, 3, &watermark, &ofs_x, &ofs_y, &op); PHALCON_VERIFY_INTERFACE_EX(*watermark, phalcon_image_adapterinterface_ce, phalcon_image_exception_ce, 0); PHALCON_MM_GROW(); image_width = phalcon_fetch_nproperty_this(this_ptr, SL("_width"), PH_NOISY TSRMLS_CC); image_height = phalcon_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY TSRMLS_CC); watermark_width = phalcon_fetch_nproperty_this(*watermark, SL("_width"), PH_NOISY TSRMLS_CC); watermark_height = phalcon_fetch_nproperty_this(*watermark, SL("_height"), PH_NOISY TSRMLS_CC); tmp_image_width = phalcon_get_intval(image_width); tmp_image_height = phalcon_get_intval(image_height); tmp_watermark_width = phalcon_get_intval(watermark_width); tmp_watermark_height = phalcon_get_intval(watermark_height); if (!ofs_x) { tmp_offset_x = (int)(((tmp_image_width - tmp_watermark_width) / 2) + 0.5); } else if (Z_TYPE_PP(ofs_x) == IS_LONG) { tmp_offset_x = Z_LVAL_PP(ofs_x); if (tmp_offset_x < 0) { tmp_offset_x = (int)(tmp_image_width - tmp_watermark_width + tmp_offset_x + 0.5); } } else if (zend_is_true(*ofs_x)) { tmp_offset_x = (int)(tmp_image_width - tmp_watermark_width); } else { tmp_offset_x = (int)(((tmp_image_width - tmp_watermark_width) / 2) + 0.5); } PHALCON_INIT_VAR(offset_x); ZVAL_LONG(offset_x, tmp_offset_x); if (!ofs_y) { tmp_offset_y = (int)(((tmp_image_height - tmp_watermark_height) / 2) + 0.5); } else if (Z_TYPE_PP(ofs_y) == IS_LONG) { tmp_offset_y = Z_LVAL_PP(ofs_y); if (tmp_offset_y < 0) { tmp_offset_y = (int)(tmp_image_height - tmp_watermark_height + tmp_offset_y + 0.5); } } else if (zend_is_true(*ofs_y)) { tmp_offset_y = (int)(tmp_image_height - tmp_watermark_height); } else { tmp_offset_y = (int)(((tmp_image_height - tmp_watermark_height) / 2) + 0.5); } PHALCON_INIT_VAR(offset_y); ZVAL_LONG(offset_y, tmp_offset_y); PHALCON_INIT_VAR(opacity); if (!op) { ZVAL_LONG(opacity, 100); } else { PHALCON_ENSURE_IS_LONG(op); if (Z_LVAL_PP(op) < 1) { ZVAL_LONG(opacity, 1); } else if (Z_LVAL_PP(op) > 100) { ZVAL_LONG(opacity, 100); } else { ZVAL_LONG(opacity, Z_LVAL_PP(op)); } } PHALCON_CALL_METHOD(NULL, this_ptr, "_watermark", *watermark, offset_x, offset_y, opacity); RETURN_THIS(); }
/** * Crop an image to the given size. Either the width or the height can be * omitted and the current width or height will be used. * * @param int $width new width * @param int $height new height * @param int $offset_x offset from the left, if it's true then will center * @param int $offset_y offset from the top, if it's true then will middle * @return Phalcon\Image\Adapter */ PHP_METHOD(Phalcon_Image_Adapter, crop) { zval **w, **h, **ofs_x = NULL, **ofs_y = NULL; zval *image_width, *image_height; zval *width, *height, *offset_x, *offset_y; long tmp_max_width, tmp_max_height, tmp_width, tmp_height, tmp_image_width, tmp_image_height, tmp_offset_x, tmp_offset_y; phalcon_fetch_params_ex(2, 2, &w, &h, &ofs_x, &ofs_y); PHALCON_ENSURE_IS_LONG(w); PHALCON_ENSURE_IS_LONG(h); PHALCON_MM_GROW(); image_width = phalcon_fetch_nproperty_this(this_ptr, SL("_width"), PH_NOISY TSRMLS_CC); image_height = phalcon_fetch_nproperty_this(this_ptr, SL("_height"), PH_NOISY TSRMLS_CC); SEPARATE_ZVAL_IF_NOT_REF(w); if (Z_TYPE_PP(w) != IS_LONG) { convert_to_long(*w); } SEPARATE_ZVAL_IF_NOT_REF(h); if (Z_TYPE_PP(h) != IS_LONG) { convert_to_long(*h); } if (ofs_x && Z_TYPE_PP(ofs_x) != IS_NULL && Z_TYPE_PP(ofs_x) != IS_BOOL && Z_TYPE_PP(ofs_x) != IS_LONG) { SEPARATE_ZVAL_IF_NOT_REF(ofs_x); convert_to_long(*ofs_x); } if (ofs_y && Z_TYPE_PP(ofs_y) != IS_NULL && Z_TYPE_PP(ofs_y) != IS_BOOL && Z_TYPE_PP(ofs_x) != IS_LONG) { SEPARATE_ZVAL_IF_NOT_REF(ofs_y); convert_to_long(*ofs_y); } tmp_width = Z_LVAL_PP(w); tmp_height = Z_LVAL_PP(h); tmp_image_width = phalcon_get_intval(image_width); tmp_image_height = phalcon_get_intval(image_height); if (tmp_width > tmp_image_width) { tmp_width = tmp_image_width; } if (tmp_height > tmp_image_height) { tmp_height = tmp_image_height; } if (!ofs_x) { tmp_offset_x = (int)(((tmp_image_width - tmp_width) / 2) + 0.5); } else if (Z_TYPE_PP(ofs_x) == IS_BOOL && PHALCON_IS_TRUE(*ofs_x)) { tmp_offset_x = tmp_image_width - tmp_width; } else if (Z_TYPE_PP(ofs_x) == IS_LONG) { if (Z_LVAL_PP(ofs_x) < 0) { tmp_offset_x = (int)(tmp_image_width - tmp_width + Z_LVAL_PP(ofs_x) + 0.5); } else { tmp_offset_x = Z_LVAL_PP(ofs_x); } } else { tmp_offset_x = (int)(((tmp_image_width - tmp_width) / 2) + 0.5); } if (!ofs_y) { tmp_offset_y = (int)(((tmp_image_height - tmp_height) / 2) + 0.5); } else if (Z_TYPE_PP(ofs_x) == IS_BOOL && PHALCON_IS_TRUE(*ofs_y)) { tmp_offset_y = tmp_image_height - tmp_height; } else if (Z_TYPE_PP(ofs_y) == IS_LONG) { if (Z_LVAL_PP(ofs_y) < 0) { tmp_offset_y = tmp_image_height - tmp_height + Z_LVAL_PP(ofs_y); } else { tmp_offset_y = Z_LVAL_PP(ofs_y); } } else { tmp_offset_y = (int)(((tmp_image_height - tmp_height) / 2) + 0.5); } tmp_max_width = tmp_image_width - tmp_offset_x; tmp_max_height = tmp_image_height - tmp_offset_y; if (tmp_width > tmp_max_width) { tmp_width = tmp_max_width; } if (tmp_height > tmp_max_height) { tmp_height = tmp_max_height; } PHALCON_ALLOC_GHOST_ZVAL(width); PHALCON_ALLOC_GHOST_ZVAL(height); PHALCON_ALLOC_GHOST_ZVAL(offset_x); PHALCON_ALLOC_GHOST_ZVAL(offset_y); ZVAL_LONG(width, tmp_width); ZVAL_LONG(height, tmp_height); ZVAL_LONG(offset_x, tmp_offset_x); ZVAL_LONG(offset_y, tmp_offset_y); PHALCON_CALL_METHOD(NULL, this_ptr, "_crop", width, height, offset_x, offset_y); RETURN_THIS(); }