Using C to implement PHP extension Image_tool picture Common processing tool class use _c language

Source: Internet
Author: User

First, class document description

Copy Code code as follows:

Class image_tool{
/**
* Construct Image_tool Object
* @param string|array $img _data
* $img _data can be the path to the picture
*/
function __construct ($img _data= "");

/**
* Add text annotations, or for text watermarks
* @access Public
* @param string $txt UTF8 encoded text
* @param float $opacity Set Transparency
* @param constant $gravity
* Set Text placement:
* Northwest,north,northeast,west, Center,east,southwest,south,southeast,static
* @param array $font font arrays can be set to the following properties:
* Name, constant, font name, if you need to add Chinese annotation, please use the Chinese font, otherwise the Chinese will display garbled.
* Supported fonts: SimSun (Arial, default), Simkai (italics), Simhei (Black), Microhei (Micron Black), Arial
* Weight, font width, int
* Size, font sizes, int
* Color, font colors, such as: "Blue", "#0000ff", "RGB (0,0,255)", and so on, default to "black";
* @return Boolean
*/
function annotate ($txt, $opacity, $gravity, array $font);

/**
* Reinitialize the object's data for multiple reuse of a Image_tool object
* @access Public
* @return void
*/
function clean ();

*
* Picture synthesis, you can do a number of pictures of the synthesis, you can also do the image watermark
* @access Public
* @param int $src _img Synthetic target picture, can be Imagetool object or picture binary data
* @param int $x to be synthesized in the x-coordinate of the canvas
* @param string $y The y-coordinate of the canvas
* @return Boolean
*
function composite ($src _img, $x, $y);

/**
* Return error message
* @access Public
* @return String
*/
function errmsg ();

/**
* Return error number
* @access Public
* @return int
*/
function Errcode ();

/**
* Perform image processing operations
* @access Public
* @param string $format
* @param boolean $display
* @return boolean|string If you set $display to True, return void, otherwise return the picture binary data. return False when failed
*/
function exec ($format, $display =false);

/**
* Flip Horizontally
* @access Public
* @return Boolean
*/
function Fliph ();

/**
* Flip Vertically
* @access Public
* @return Boolean
*/
function FLIPV ();

/**
* Get Picture Properties
* @access Public
* @return Array|boolean Error return False
*/
function getimageattr ();

/**
* Noise reduction, improve picture quality, usually used before exec
* @access Public
* @return Boolean
*/
function improve ();

/**
* Scaling the picture, only specify width or height, will be equal scaling
* @access Public
* @param int $width
* @param int $height
* @param boolean $thumbnail clear picture additional information
* @return Boolean
*/
function Resize ($width, $height, $thumbnail =true);

/**
* Scaled proportionally. 1 is the original size
* @access Public
* @param float $ratio
* @param boolean $thumbnail clear picture additional information
* @return Boolean
*/
function Resizeratio ($ratio, $thumbnail =true);

/**
* Rotate the picture clockwise
* @access Public
* @param int $degree rotation degrees (0-360)
* @return Boolean
*/
function rotate ($degree =90);

/**
* Set the image binary data to be processed
* @access Public
* @param string $img _blob
* @return Boolean
*/
function SetData ($img _blob);
}

third, the expansion of implementation
1.php_fetch_url.h
Copy Code code as follows:

/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2012 the PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| That's bundled with this package in the file LICENSE, and is |
| Available through the World-wide-web at the following URL: |
| Http://www.php.net/license/3_01.txt |
| If you don't receive a copy of the PHP license and are unable to | did
| Obtain it through the World-wide-web, please send a note to |
|               License@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: |
+----------------------------------------------------------------------+
*/

/* $Id $ */

#ifndef Php_image_tool_h
#define Php_image_tool_h

extern zend_module_entry Image_tool_module_entry;
#define PHPEXT_IMAGE_TOOL_PTR &image_tool_module_entry

#ifdef PHP_WIN32
# define PHP_IMAGE_TOOL_API __declspec (dllexport)
#elif defined (__gnuc__) && __gnuc__ >= 4
# define PHP_IMAGE_TOOL_API __attribute__ ((Visibility ("default"))
#else
# define Php_image_tool_api
#endif

#ifdef ZTS
#include "TSRM.h"
#endif

#define Fetch_this z_objce_p (Getthis ()), Getthis ()
#define IMAGETOOL_MAGICKWAND_RSRC_NAME "Magickwand"
#define IMAGETOOL_PIXELWAND_RSRC_NAME "Pixelwand"

#define IMAGETOOL_NORTHWEST 1
#define Imagetool_north 2
#define IMAGETOOL_NORTHEAST 3
#define IMAGETOOL_WEST 4
#define Imagetool_center 5
#define IMAGETOOL_EAST 6
#define IMAGETOOL_SOUTHWEST 7
#define Imagetool_south 8
#define IMAGETOOL_SOUTHEAST 9
#define Imagetool_static 10

#define IMAGETOOL_TOP_LEFT 1
#define Imagetool_top_center 2
#define Imagetool_top_right 3
#define IMAGETOOL_CENTER_LEFT 4
#define Imagetool_center_center 5
#define Imagetool_center_right 6
#define IMAGETOOL_BOTTOM_LEFT 7
#define Imagetool_bottom_center 8
#define Imagetool_bottom_right 9

#define Get_magick_wand (Zval, magick_wand) Zval = Zend_read_property (Fetch_this, Zend_strl ("Magick_wand"), 0 TSRMLS_CC );\
Zend_fetch_resource_no_return (Magick_wand, magickwand*, &zval,-1, Imagetool_magickwand_rsrc_name, Le_image_ Wand);

Php_minit_function (Image_tool);
Php_mshutdown_function (Image_tool);
Php_rinit_function (Image_tool);
Php_rshutdown_function (Image_tool);
Php_minfo_function (Image_tool);


#ifdef ZTS
#define IMAGE_TOOL_G (v) tsrmg (image_tool_globals_id, zend_image_tool_globals *, V)
#else
#define IMAGE_TOOL_G (v) (IMAGE_TOOL_GLOBALS.V)
#endif

#endif/* Php_image_tool_h * *


SOURCE Download Address: Http://l9.yunpan.cn/lk/QEcqyYY6zy9YR

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.