PageRenderTime 66ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/gd/gd.c

http://github.com/infusion/PHP
C | 5051 lines | 3747 code | 762 blank | 542 comment | 583 complexity | d6bbacde544a6a10fdc6711b59623ed9 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-3-Clause
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2011 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Rasmus Lerdorf <rasmus@php.net> |
  16. | Stig Bakken <ssb@php.net> |
  17. | Jim Winstead <jimw@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* $Id: gd.c 306939 2011-01-01 02:19:59Z felipe $ */
  21. /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
  22. Cold Spring Harbor Labs. */
  23. /* Note that there is no code from the gd package in this file */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include "php.h"
  28. #include "php_ini.h"
  29. #include "ext/standard/head.h"
  30. #include <math.h>
  31. #include "SAPI.h"
  32. #include "php_gd.h"
  33. #include "ext/standard/info.h"
  34. #include "php_open_temporary_file.h"
  35. #if HAVE_SYS_WAIT_H
  36. # include <sys/wait.h>
  37. #endif
  38. #if HAVE_UNISTD_H
  39. # include <unistd.h>
  40. #endif
  41. #ifdef PHP_WIN32
  42. # include <io.h>
  43. # include <fcntl.h>
  44. # include <windows.h>
  45. # include <Winuser.h>
  46. # include <Wingdi.h>
  47. #endif
  48. #if HAVE_LIBGD
  49. #if !HAVE_GD_BUNDLED
  50. # include "libgd/gd_compat.h"
  51. #endif
  52. static int le_gd, le_gd_font;
  53. #if HAVE_LIBT1
  54. #include <t1lib.h>
  55. static int le_ps_font, le_ps_enc;
  56. static void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  57. static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC);
  58. #endif
  59. #include <gd.h>
  60. #include <gdfontt.h> /* 1 Tiny font */
  61. #include <gdfonts.h> /* 2 Small font */
  62. #include <gdfontmb.h> /* 3 Medium bold font */
  63. #include <gdfontl.h> /* 4 Large font */
  64. #include <gdfontg.h> /* 5 Giant font */
  65. #ifdef HAVE_GD_WBMP
  66. #include "libgd/wbmp.h"
  67. #endif
  68. #ifdef ENABLE_GD_TTF
  69. # ifdef HAVE_LIBFREETYPE
  70. # include <ft2build.h>
  71. # include FT_FREETYPE_H
  72. # endif
  73. #endif
  74. #ifndef M_PI
  75. #define M_PI 3.14159265358979323846
  76. #endif
  77. #ifdef ENABLE_GD_TTF
  78. static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int);
  79. #endif
  80. #if HAVE_LIBGD15
  81. /* it's >= 1.5, i.e. has IOCtx */
  82. #define USE_GD_IOCTX 1
  83. #else
  84. #undef USE_GD_IOCTX
  85. #endif
  86. #ifdef USE_GD_IOCTX
  87. #include "gd_ctx.c"
  88. #else
  89. #define gdImageCreateFromGdCtx NULL
  90. #define gdImageCreateFromGd2Ctx NULL
  91. #define gdImageCreateFromGd2partCtx NULL
  92. #define gdImageCreateFromGifCtx NULL
  93. #define gdImageCreateFromJpegCtx NULL
  94. #define gdImageCreateFromPngCtx NULL
  95. #define gdImageCreateFromWBMPCtx NULL
  96. typedef FILE gdIOCtx;
  97. #define CTX_PUTC(c, fp) fputc(c, fp)
  98. #endif
  99. #ifndef HAVE_GDIMAGECOLORRESOLVE
  100. extern int gdImageColorResolve(gdImagePtr, int, int, int);
  101. #endif
  102. #if HAVE_COLORCLOSESTHWB
  103. int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
  104. #endif
  105. #ifndef HAVE_GD_DYNAMIC_CTX_EX
  106. #define gdNewDynamicCtxEx(len, data, val) gdNewDynamicCtx(len, data)
  107. #endif
  108. /* Section Filters Declarations */
  109. /* IMPORTANT NOTE FOR NEW FILTER
  110. * Do not forget to update:
  111. * IMAGE_FILTER_MAX: define the last filter index
  112. * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments
  113. * image_filter array in PHP_FUNCTION(imagefilter)
  114. * */
  115. #define IMAGE_FILTER_NEGATE 0
  116. #define IMAGE_FILTER_GRAYSCALE 1
  117. #define IMAGE_FILTER_BRIGHTNESS 2
  118. #define IMAGE_FILTER_CONTRAST 3
  119. #define IMAGE_FILTER_COLORIZE 4
  120. #define IMAGE_FILTER_EDGEDETECT 5
  121. #define IMAGE_FILTER_EMBOSS 6
  122. #define IMAGE_FILTER_GAUSSIAN_BLUR 7
  123. #define IMAGE_FILTER_SELECTIVE_BLUR 8
  124. #define IMAGE_FILTER_MEAN_REMOVAL 9
  125. #define IMAGE_FILTER_SMOOTH 10
  126. #define IMAGE_FILTER_PIXELATE 11
  127. #define IMAGE_FILTER_MAX 11
  128. #define IMAGE_FILTER_MAX_ARGS 6
  129. static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS);
  130. static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS);
  131. static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS);
  132. static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS);
  133. static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS);
  134. static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS);
  135. static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS);
  136. static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS);
  137. static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
  138. static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
  139. static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
  140. static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS);
  141. /* End Section filters declarations */
  142. static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC);
  143. static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)());
  144. static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)());
  145. static int _php_image_type(char data[8]);
  146. static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type);
  147. static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold);
  148. /* {{{ arginfo */
  149. ZEND_BEGIN_ARG_INFO(arginfo_gd_info, 0)
  150. ZEND_END_ARG_INFO()
  151. ZEND_BEGIN_ARG_INFO(arginfo_imageloadfont, 0)
  152. ZEND_ARG_INFO(0, filename)
  153. ZEND_END_ARG_INFO()
  154. ZEND_BEGIN_ARG_INFO(arginfo_imagesetstyle, 0)
  155. ZEND_ARG_INFO(0, im)
  156. ZEND_ARG_INFO(0, styles) /* ARRAY_INFO(0, styles, 0) */
  157. ZEND_END_ARG_INFO()
  158. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatetruecolor, 0)
  159. ZEND_ARG_INFO(0, x_size)
  160. ZEND_ARG_INFO(0, y_size)
  161. ZEND_END_ARG_INFO()
  162. ZEND_BEGIN_ARG_INFO(arginfo_imageistruecolor, 0)
  163. ZEND_ARG_INFO(0, im)
  164. ZEND_END_ARG_INFO()
  165. ZEND_BEGIN_ARG_INFO(arginfo_imagetruecolortopalette, 0)
  166. ZEND_ARG_INFO(0, im)
  167. ZEND_ARG_INFO(0, ditherFlag)
  168. ZEND_ARG_INFO(0, colorsWanted)
  169. ZEND_END_ARG_INFO()
  170. ZEND_BEGIN_ARG_INFO(arginfo_imagecolormatch, 0)
  171. ZEND_ARG_INFO(0, im1)
  172. ZEND_ARG_INFO(0, im2)
  173. ZEND_END_ARG_INFO()
  174. ZEND_BEGIN_ARG_INFO(arginfo_imagesetthickness, 0)
  175. ZEND_ARG_INFO(0, im)
  176. ZEND_ARG_INFO(0, thickness)
  177. ZEND_END_ARG_INFO()
  178. ZEND_BEGIN_ARG_INFO(arginfo_imagefilledellipse, 0)
  179. ZEND_ARG_INFO(0, im)
  180. ZEND_ARG_INFO(0, cx)
  181. ZEND_ARG_INFO(0, cy)
  182. ZEND_ARG_INFO(0, w)
  183. ZEND_ARG_INFO(0, h)
  184. ZEND_ARG_INFO(0, color)
  185. ZEND_END_ARG_INFO()
  186. ZEND_BEGIN_ARG_INFO(arginfo_imagefilledarc, 0)
  187. ZEND_ARG_INFO(0, im)
  188. ZEND_ARG_INFO(0, cx)
  189. ZEND_ARG_INFO(0, cy)
  190. ZEND_ARG_INFO(0, w)
  191. ZEND_ARG_INFO(0, h)
  192. ZEND_ARG_INFO(0, s)
  193. ZEND_ARG_INFO(0, e)
  194. ZEND_ARG_INFO(0, col)
  195. ZEND_ARG_INFO(0, style)
  196. ZEND_END_ARG_INFO()
  197. ZEND_BEGIN_ARG_INFO(arginfo_imagealphablending, 0)
  198. ZEND_ARG_INFO(0, im)
  199. ZEND_ARG_INFO(0, blend)
  200. ZEND_END_ARG_INFO()
  201. ZEND_BEGIN_ARG_INFO(arginfo_imagesavealpha, 0)
  202. ZEND_ARG_INFO(0, im)
  203. ZEND_ARG_INFO(0, save)
  204. ZEND_END_ARG_INFO()
  205. #if HAVE_GD_BUNDLED
  206. ZEND_BEGIN_ARG_INFO(arginfo_imagelayereffect, 0)
  207. ZEND_ARG_INFO(0, im)
  208. ZEND_ARG_INFO(0, effect)
  209. ZEND_END_ARG_INFO()
  210. #endif
  211. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocatealpha, 0)
  212. ZEND_ARG_INFO(0, im)
  213. ZEND_ARG_INFO(0, red)
  214. ZEND_ARG_INFO(0, green)
  215. ZEND_ARG_INFO(0, blue)
  216. ZEND_ARG_INFO(0, alpha)
  217. ZEND_END_ARG_INFO()
  218. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolvealpha, 0)
  219. ZEND_ARG_INFO(0, im)
  220. ZEND_ARG_INFO(0, red)
  221. ZEND_ARG_INFO(0, green)
  222. ZEND_ARG_INFO(0, blue)
  223. ZEND_ARG_INFO(0, alpha)
  224. ZEND_END_ARG_INFO()
  225. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosestalpha, 0)
  226. ZEND_ARG_INFO(0, im)
  227. ZEND_ARG_INFO(0, red)
  228. ZEND_ARG_INFO(0, green)
  229. ZEND_ARG_INFO(0, blue)
  230. ZEND_ARG_INFO(0, alpha)
  231. ZEND_END_ARG_INFO()
  232. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexactalpha, 0)
  233. ZEND_ARG_INFO(0, im)
  234. ZEND_ARG_INFO(0, red)
  235. ZEND_ARG_INFO(0, green)
  236. ZEND_ARG_INFO(0, blue)
  237. ZEND_ARG_INFO(0, alpha)
  238. ZEND_END_ARG_INFO()
  239. ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresampled, 0)
  240. ZEND_ARG_INFO(0, dst_im)
  241. ZEND_ARG_INFO(0, src_im)
  242. ZEND_ARG_INFO(0, dst_x)
  243. ZEND_ARG_INFO(0, dst_y)
  244. ZEND_ARG_INFO(0, src_x)
  245. ZEND_ARG_INFO(0, src_y)
  246. ZEND_ARG_INFO(0, dst_w)
  247. ZEND_ARG_INFO(0, dst_h)
  248. ZEND_ARG_INFO(0, src_w)
  249. ZEND_ARG_INFO(0, src_h)
  250. ZEND_END_ARG_INFO()
  251. #ifdef PHP_WIN32
  252. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegrabwindow, 0, 0, 1)
  253. ZEND_ARG_INFO(0, handle)
  254. ZEND_ARG_INFO(0, client_area)
  255. ZEND_END_ARG_INFO()
  256. ZEND_BEGIN_ARG_INFO(arginfo_imagegrabscreen, 0)
  257. ZEND_END_ARG_INFO()
  258. #endif
  259. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagerotate, 0, 0, 3)
  260. ZEND_ARG_INFO(0, im)
  261. ZEND_ARG_INFO(0, angle)
  262. ZEND_ARG_INFO(0, bgdcolor)
  263. ZEND_ARG_INFO(0, ignoretransparent)
  264. ZEND_END_ARG_INFO()
  265. #if HAVE_GD_IMAGESETTILE
  266. ZEND_BEGIN_ARG_INFO(arginfo_imagesettile, 0)
  267. ZEND_ARG_INFO(0, im)
  268. ZEND_ARG_INFO(0, tile)
  269. ZEND_END_ARG_INFO()
  270. #endif
  271. #if HAVE_GD_IMAGESETBRUSH
  272. ZEND_BEGIN_ARG_INFO(arginfo_imagesetbrush, 0)
  273. ZEND_ARG_INFO(0, im)
  274. ZEND_ARG_INFO(0, brush)
  275. ZEND_END_ARG_INFO()
  276. #endif
  277. ZEND_BEGIN_ARG_INFO(arginfo_imagecreate, 0)
  278. ZEND_ARG_INFO(0, x_size)
  279. ZEND_ARG_INFO(0, y_size)
  280. ZEND_END_ARG_INFO()
  281. ZEND_BEGIN_ARG_INFO(arginfo_imagetypes, 0)
  282. ZEND_END_ARG_INFO()
  283. #if HAVE_LIBGD15
  284. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromstring, 0)
  285. ZEND_ARG_INFO(0, image)
  286. ZEND_END_ARG_INFO()
  287. #endif
  288. #ifdef HAVE_GD_GIF_READ
  289. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgif, 0)
  290. ZEND_ARG_INFO(0, filename)
  291. ZEND_END_ARG_INFO()
  292. #endif
  293. #ifdef HAVE_GD_JPG
  294. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromjpeg, 0)
  295. ZEND_ARG_INFO(0, filename)
  296. ZEND_END_ARG_INFO()
  297. #endif
  298. #ifdef HAVE_GD_PNG
  299. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefrompng, 0)
  300. ZEND_ARG_INFO(0, filename)
  301. ZEND_END_ARG_INFO()
  302. #endif
  303. #ifdef HAVE_GD_XBM
  304. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0)
  305. ZEND_ARG_INFO(0, filename)
  306. ZEND_END_ARG_INFO()
  307. #endif
  308. #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
  309. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxpm, 0)
  310. ZEND_ARG_INFO(0, filename)
  311. ZEND_END_ARG_INFO()
  312. #endif
  313. #ifdef HAVE_GD_WBMP
  314. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromwbmp, 0)
  315. ZEND_ARG_INFO(0, filename)
  316. ZEND_END_ARG_INFO()
  317. #endif
  318. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd, 0)
  319. ZEND_ARG_INFO(0, filename)
  320. ZEND_END_ARG_INFO()
  321. #ifdef HAVE_GD_GD2
  322. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2, 0)
  323. ZEND_ARG_INFO(0, filename)
  324. ZEND_END_ARG_INFO()
  325. ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromgd2part, 0)
  326. ZEND_ARG_INFO(0, filename)
  327. ZEND_ARG_INFO(0, srcX)
  328. ZEND_ARG_INFO(0, srcY)
  329. ZEND_ARG_INFO(0, width)
  330. ZEND_ARG_INFO(0, height)
  331. ZEND_END_ARG_INFO()
  332. #endif
  333. #if HAVE_GD_BUNDLED
  334. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagexbm, 0, 0, 2)
  335. ZEND_ARG_INFO(0, im)
  336. ZEND_ARG_INFO(0, filename)
  337. ZEND_ARG_INFO(0, foreground)
  338. ZEND_END_ARG_INFO()
  339. #endif
  340. #ifdef HAVE_GD_GIF_CREATE
  341. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegif, 0, 0, 1)
  342. ZEND_ARG_INFO(0, im)
  343. ZEND_ARG_INFO(0, filename)
  344. ZEND_END_ARG_INFO()
  345. #endif
  346. #ifdef HAVE_GD_PNG
  347. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepng, 0, 0, 1)
  348. ZEND_ARG_INFO(0, im)
  349. ZEND_ARG_INFO(0, filename)
  350. ZEND_END_ARG_INFO()
  351. #endif
  352. #ifdef HAVE_GD_JPG
  353. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagejpeg, 0, 0, 1)
  354. ZEND_ARG_INFO(0, im)
  355. ZEND_ARG_INFO(0, filename)
  356. ZEND_ARG_INFO(0, quality)
  357. ZEND_END_ARG_INFO()
  358. #endif
  359. #ifdef HAVE_GD_WBMP
  360. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewbmp, 0, 0, 1)
  361. ZEND_ARG_INFO(0, im)
  362. ZEND_ARG_INFO(0, filename)
  363. ZEND_ARG_INFO(0, foreground)
  364. ZEND_END_ARG_INFO()
  365. #endif
  366. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd, 0, 0, 1)
  367. ZEND_ARG_INFO(0, im)
  368. ZEND_ARG_INFO(0, filename)
  369. ZEND_END_ARG_INFO()
  370. #ifdef HAVE_GD_GD2
  371. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagegd2, 0, 0, 1)
  372. ZEND_ARG_INFO(0, im)
  373. ZEND_ARG_INFO(0, filename)
  374. ZEND_ARG_INFO(0, chunk_size)
  375. ZEND_ARG_INFO(0, type)
  376. ZEND_END_ARG_INFO()
  377. #endif
  378. ZEND_BEGIN_ARG_INFO(arginfo_imagedestroy, 0)
  379. ZEND_ARG_INFO(0, im)
  380. ZEND_END_ARG_INFO()
  381. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorallocate, 0)
  382. ZEND_ARG_INFO(0, im)
  383. ZEND_ARG_INFO(0, red)
  384. ZEND_ARG_INFO(0, green)
  385. ZEND_ARG_INFO(0, blue)
  386. ZEND_END_ARG_INFO()
  387. #if HAVE_LIBGD15
  388. ZEND_BEGIN_ARG_INFO(arginfo_imagepalettecopy, 0)
  389. ZEND_ARG_INFO(0, dst)
  390. ZEND_ARG_INFO(0, src)
  391. ZEND_END_ARG_INFO()
  392. #endif
  393. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorat, 0)
  394. ZEND_ARG_INFO(0, im)
  395. ZEND_ARG_INFO(0, x)
  396. ZEND_ARG_INFO(0, y)
  397. ZEND_END_ARG_INFO()
  398. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosest, 0)
  399. ZEND_ARG_INFO(0, im)
  400. ZEND_ARG_INFO(0, red)
  401. ZEND_ARG_INFO(0, green)
  402. ZEND_ARG_INFO(0, blue)
  403. ZEND_END_ARG_INFO()
  404. #if HAVE_COLORCLOSESTHWB
  405. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorclosesthwb, 0)
  406. ZEND_ARG_INFO(0, im)
  407. ZEND_ARG_INFO(0, red)
  408. ZEND_ARG_INFO(0, green)
  409. ZEND_ARG_INFO(0, blue)
  410. ZEND_END_ARG_INFO()
  411. #endif
  412. ZEND_BEGIN_ARG_INFO(arginfo_imagecolordeallocate, 0)
  413. ZEND_ARG_INFO(0, im)
  414. ZEND_ARG_INFO(0, index)
  415. ZEND_END_ARG_INFO()
  416. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorresolve, 0)
  417. ZEND_ARG_INFO(0, im)
  418. ZEND_ARG_INFO(0, red)
  419. ZEND_ARG_INFO(0, green)
  420. ZEND_ARG_INFO(0, blue)
  421. ZEND_END_ARG_INFO()
  422. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexact, 0)
  423. ZEND_ARG_INFO(0, im)
  424. ZEND_ARG_INFO(0, red)
  425. ZEND_ARG_INFO(0, green)
  426. ZEND_ARG_INFO(0, blue)
  427. ZEND_END_ARG_INFO()
  428. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorset, 0)
  429. ZEND_ARG_INFO(0, im)
  430. ZEND_ARG_INFO(0, color)
  431. ZEND_ARG_INFO(0, red)
  432. ZEND_ARG_INFO(0, green)
  433. ZEND_ARG_INFO(0, blue)
  434. ZEND_END_ARG_INFO()
  435. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorsforindex, 0)
  436. ZEND_ARG_INFO(0, im)
  437. ZEND_ARG_INFO(0, index)
  438. ZEND_END_ARG_INFO()
  439. ZEND_BEGIN_ARG_INFO(arginfo_imagegammacorrect, 0)
  440. ZEND_ARG_INFO(0, im)
  441. ZEND_ARG_INFO(0, inputgamma)
  442. ZEND_ARG_INFO(0, outputgamma)
  443. ZEND_END_ARG_INFO()
  444. ZEND_BEGIN_ARG_INFO(arginfo_imagesetpixel, 0)
  445. ZEND_ARG_INFO(0, im)
  446. ZEND_ARG_INFO(0, x)
  447. ZEND_ARG_INFO(0, y)
  448. ZEND_ARG_INFO(0, col)
  449. ZEND_END_ARG_INFO()
  450. ZEND_BEGIN_ARG_INFO(arginfo_imageline, 0)
  451. ZEND_ARG_INFO(0, im)
  452. ZEND_ARG_INFO(0, x1)
  453. ZEND_ARG_INFO(0, y1)
  454. ZEND_ARG_INFO(0, x2)
  455. ZEND_ARG_INFO(0, y2)
  456. ZEND_ARG_INFO(0, col)
  457. ZEND_END_ARG_INFO()
  458. ZEND_BEGIN_ARG_INFO(arginfo_imagedashedline, 0)
  459. ZEND_ARG_INFO(0, im)
  460. ZEND_ARG_INFO(0, x1)
  461. ZEND_ARG_INFO(0, y1)
  462. ZEND_ARG_INFO(0, x2)
  463. ZEND_ARG_INFO(0, y2)
  464. ZEND_ARG_INFO(0, col)
  465. ZEND_END_ARG_INFO()
  466. ZEND_BEGIN_ARG_INFO(arginfo_imagerectangle, 0)
  467. ZEND_ARG_INFO(0, im)
  468. ZEND_ARG_INFO(0, x1)
  469. ZEND_ARG_INFO(0, y1)
  470. ZEND_ARG_INFO(0, x2)
  471. ZEND_ARG_INFO(0, y2)
  472. ZEND_ARG_INFO(0, col)
  473. ZEND_END_ARG_INFO()
  474. ZEND_BEGIN_ARG_INFO(arginfo_imagefilledrectangle, 0)
  475. ZEND_ARG_INFO(0, im)
  476. ZEND_ARG_INFO(0, x1)
  477. ZEND_ARG_INFO(0, y1)
  478. ZEND_ARG_INFO(0, x2)
  479. ZEND_ARG_INFO(0, y2)
  480. ZEND_ARG_INFO(0, col)
  481. ZEND_END_ARG_INFO()
  482. ZEND_BEGIN_ARG_INFO(arginfo_imagearc, 0)
  483. ZEND_ARG_INFO(0, im)
  484. ZEND_ARG_INFO(0, cx)
  485. ZEND_ARG_INFO(0, cy)
  486. ZEND_ARG_INFO(0, w)
  487. ZEND_ARG_INFO(0, h)
  488. ZEND_ARG_INFO(0, s)
  489. ZEND_ARG_INFO(0, e)
  490. ZEND_ARG_INFO(0, col)
  491. ZEND_END_ARG_INFO()
  492. ZEND_BEGIN_ARG_INFO(arginfo_imageellipse, 0)
  493. ZEND_ARG_INFO(0, im)
  494. ZEND_ARG_INFO(0, cx)
  495. ZEND_ARG_INFO(0, cy)
  496. ZEND_ARG_INFO(0, w)
  497. ZEND_ARG_INFO(0, h)
  498. ZEND_ARG_INFO(0, color)
  499. ZEND_END_ARG_INFO()
  500. ZEND_BEGIN_ARG_INFO(arginfo_imagefilltoborder, 0)
  501. ZEND_ARG_INFO(0, im)
  502. ZEND_ARG_INFO(0, x)
  503. ZEND_ARG_INFO(0, y)
  504. ZEND_ARG_INFO(0, border)
  505. ZEND_ARG_INFO(0, col)
  506. ZEND_END_ARG_INFO()
  507. ZEND_BEGIN_ARG_INFO(arginfo_imagefill, 0)
  508. ZEND_ARG_INFO(0, im)
  509. ZEND_ARG_INFO(0, x)
  510. ZEND_ARG_INFO(0, y)
  511. ZEND_ARG_INFO(0, col)
  512. ZEND_END_ARG_INFO()
  513. ZEND_BEGIN_ARG_INFO(arginfo_imagecolorstotal, 0)
  514. ZEND_ARG_INFO(0, im)
  515. ZEND_END_ARG_INFO()
  516. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolortransparent, 0, 0, 1)
  517. ZEND_ARG_INFO(0, im)
  518. ZEND_ARG_INFO(0, col)
  519. ZEND_END_ARG_INFO()
  520. ZEND_BEGIN_ARG_INFO_EX(arginfo_imageinterlace, 0, 0, 1)
  521. ZEND_ARG_INFO(0, im)
  522. ZEND_ARG_INFO(0, interlace)
  523. ZEND_END_ARG_INFO()
  524. ZEND_BEGIN_ARG_INFO(arginfo_imagepolygon, 0)
  525. ZEND_ARG_INFO(0, im)
  526. ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
  527. ZEND_ARG_INFO(0, num_pos)
  528. ZEND_ARG_INFO(0, col)
  529. ZEND_END_ARG_INFO()
  530. ZEND_BEGIN_ARG_INFO(arginfo_imagefilledpolygon, 0)
  531. ZEND_ARG_INFO(0, im)
  532. ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */
  533. ZEND_ARG_INFO(0, num_pos)
  534. ZEND_ARG_INFO(0, col)
  535. ZEND_END_ARG_INFO()
  536. ZEND_BEGIN_ARG_INFO(arginfo_imagefontwidth, 0)
  537. ZEND_ARG_INFO(0, font)
  538. ZEND_END_ARG_INFO()
  539. ZEND_BEGIN_ARG_INFO(arginfo_imagefontheight, 0)
  540. ZEND_ARG_INFO(0, font)
  541. ZEND_END_ARG_INFO()
  542. ZEND_BEGIN_ARG_INFO(arginfo_imagechar, 0)
  543. ZEND_ARG_INFO(0, im)
  544. ZEND_ARG_INFO(0, font)
  545. ZEND_ARG_INFO(0, x)
  546. ZEND_ARG_INFO(0, y)
  547. ZEND_ARG_INFO(0, c)
  548. ZEND_ARG_INFO(0, col)
  549. ZEND_END_ARG_INFO()
  550. ZEND_BEGIN_ARG_INFO(arginfo_imagecharup, 0)
  551. ZEND_ARG_INFO(0, im)
  552. ZEND_ARG_INFO(0, font)
  553. ZEND_ARG_INFO(0, x)
  554. ZEND_ARG_INFO(0, y)
  555. ZEND_ARG_INFO(0, c)
  556. ZEND_ARG_INFO(0, col)
  557. ZEND_END_ARG_INFO()
  558. ZEND_BEGIN_ARG_INFO(arginfo_imagestring, 0)
  559. ZEND_ARG_INFO(0, im)
  560. ZEND_ARG_INFO(0, font)
  561. ZEND_ARG_INFO(0, x)
  562. ZEND_ARG_INFO(0, y)
  563. ZEND_ARG_INFO(0, str)
  564. ZEND_ARG_INFO(0, col)
  565. ZEND_END_ARG_INFO()
  566. ZEND_BEGIN_ARG_INFO(arginfo_imagestringup, 0)
  567. ZEND_ARG_INFO(0, im)
  568. ZEND_ARG_INFO(0, font)
  569. ZEND_ARG_INFO(0, x)
  570. ZEND_ARG_INFO(0, y)
  571. ZEND_ARG_INFO(0, str)
  572. ZEND_ARG_INFO(0, col)
  573. ZEND_END_ARG_INFO()
  574. ZEND_BEGIN_ARG_INFO(arginfo_imagecopy, 0)
  575. ZEND_ARG_INFO(0, dst_im)
  576. ZEND_ARG_INFO(0, src_im)
  577. ZEND_ARG_INFO(0, dst_x)
  578. ZEND_ARG_INFO(0, dst_y)
  579. ZEND_ARG_INFO(0, src_x)
  580. ZEND_ARG_INFO(0, src_y)
  581. ZEND_ARG_INFO(0, src_w)
  582. ZEND_ARG_INFO(0, src_h)
  583. ZEND_END_ARG_INFO()
  584. #if HAVE_LIBGD15
  585. ZEND_BEGIN_ARG_INFO(arginfo_imagecopymerge, 0)
  586. ZEND_ARG_INFO(0, src_im)
  587. ZEND_ARG_INFO(0, dst_im)
  588. ZEND_ARG_INFO(0, dst_x)
  589. ZEND_ARG_INFO(0, dst_y)
  590. ZEND_ARG_INFO(0, src_x)
  591. ZEND_ARG_INFO(0, src_y)
  592. ZEND_ARG_INFO(0, src_w)
  593. ZEND_ARG_INFO(0, src_h)
  594. ZEND_ARG_INFO(0, pct)
  595. ZEND_END_ARG_INFO()
  596. ZEND_BEGIN_ARG_INFO(arginfo_imagecopymergegray, 0)
  597. ZEND_ARG_INFO(0, src_im)
  598. ZEND_ARG_INFO(0, dst_im)
  599. ZEND_ARG_INFO(0, dst_x)
  600. ZEND_ARG_INFO(0, dst_y)
  601. ZEND_ARG_INFO(0, src_x)
  602. ZEND_ARG_INFO(0, src_y)
  603. ZEND_ARG_INFO(0, src_w)
  604. ZEND_ARG_INFO(0, src_h)
  605. ZEND_ARG_INFO(0, pct)
  606. ZEND_END_ARG_INFO()
  607. #endif
  608. ZEND_BEGIN_ARG_INFO(arginfo_imagecopyresized, 0)
  609. ZEND_ARG_INFO(0, dst_im)
  610. ZEND_ARG_INFO(0, src_im)
  611. ZEND_ARG_INFO(0, dst_x)
  612. ZEND_ARG_INFO(0, dst_y)
  613. ZEND_ARG_INFO(0, src_x)
  614. ZEND_ARG_INFO(0, src_y)
  615. ZEND_ARG_INFO(0, dst_w)
  616. ZEND_ARG_INFO(0, dst_h)
  617. ZEND_ARG_INFO(0, src_w)
  618. ZEND_ARG_INFO(0, src_h)
  619. ZEND_END_ARG_INFO()
  620. ZEND_BEGIN_ARG_INFO(arginfo_imagesx, 0)
  621. ZEND_ARG_INFO(0, im)
  622. ZEND_END_ARG_INFO()
  623. ZEND_BEGIN_ARG_INFO(arginfo_imagesy, 0)
  624. ZEND_ARG_INFO(0, im)
  625. ZEND_END_ARG_INFO()
  626. #ifdef ENABLE_GD_TTF
  627. #if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
  628. ZEND_BEGIN_ARG_INFO_EX(arginfo_imageftbbox, 0, 0, 4)
  629. ZEND_ARG_INFO(0, size)
  630. ZEND_ARG_INFO(0, angle)
  631. ZEND_ARG_INFO(0, font_file)
  632. ZEND_ARG_INFO(0, text)
  633. ZEND_ARG_INFO(0, extrainfo) /* ARRAY_INFO(0, extrainfo, 0) */
  634. ZEND_END_ARG_INFO()
  635. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefttext, 0, 0, 8)
  636. ZEND_ARG_INFO(0, im)
  637. ZEND_ARG_INFO(0, size)
  638. ZEND_ARG_INFO(0, angle)
  639. ZEND_ARG_INFO(0, x)
  640. ZEND_ARG_INFO(0, y)
  641. ZEND_ARG_INFO(0, col)
  642. ZEND_ARG_INFO(0, font_file)
  643. ZEND_ARG_INFO(0, text)
  644. ZEND_ARG_INFO(0, extrainfo) /* ARRAY_INFO(0, extrainfo, 0) */
  645. ZEND_END_ARG_INFO()
  646. #endif
  647. ZEND_BEGIN_ARG_INFO(arginfo_imagettfbbox, 0)
  648. ZEND_ARG_INFO(0, size)
  649. ZEND_ARG_INFO(0, angle)
  650. ZEND_ARG_INFO(0, font_file)
  651. ZEND_ARG_INFO(0, text)
  652. ZEND_END_ARG_INFO()
  653. ZEND_BEGIN_ARG_INFO(arginfo_imagettftext, 0)
  654. ZEND_ARG_INFO(0, im)
  655. ZEND_ARG_INFO(0, size)
  656. ZEND_ARG_INFO(0, angle)
  657. ZEND_ARG_INFO(0, x)
  658. ZEND_ARG_INFO(0, y)
  659. ZEND_ARG_INFO(0, col)
  660. ZEND_ARG_INFO(0, font_file)
  661. ZEND_ARG_INFO(0, text)
  662. ZEND_END_ARG_INFO()
  663. #endif
  664. #ifdef HAVE_LIBT1
  665. ZEND_BEGIN_ARG_INFO(arginfo_imagepsloadfont, 0)
  666. ZEND_ARG_INFO(0, pathname)
  667. ZEND_END_ARG_INFO()
  668. /*
  669. ZEND_BEGIN_ARG_INFO(arginfo_imagepscopyfont, 0)
  670. ZEND_ARG_INFO(0, font_index)
  671. ZEND_END_ARG_INFO()
  672. */
  673. ZEND_BEGIN_ARG_INFO(arginfo_imagepsfreefont, 0)
  674. ZEND_ARG_INFO(0, font_index)
  675. ZEND_END_ARG_INFO()
  676. ZEND_BEGIN_ARG_INFO(arginfo_imagepsencodefont, 0)
  677. ZEND_ARG_INFO(0, font_index)
  678. ZEND_ARG_INFO(0, filename)
  679. ZEND_END_ARG_INFO()
  680. ZEND_BEGIN_ARG_INFO(arginfo_imagepsextendfont, 0)
  681. ZEND_ARG_INFO(0, font_index)
  682. ZEND_ARG_INFO(0, extend)
  683. ZEND_END_ARG_INFO()
  684. ZEND_BEGIN_ARG_INFO(arginfo_imagepsslantfont, 0)
  685. ZEND_ARG_INFO(0, font_index)
  686. ZEND_ARG_INFO(0, slant)
  687. ZEND_END_ARG_INFO()
  688. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepstext, 0, 0, 8)
  689. ZEND_ARG_INFO(0, im)
  690. ZEND_ARG_INFO(0, text)
  691. ZEND_ARG_INFO(0, font)
  692. ZEND_ARG_INFO(0, size)
  693. ZEND_ARG_INFO(0, foreground)
  694. ZEND_ARG_INFO(0, background)
  695. ZEND_ARG_INFO(0, xcoord)
  696. ZEND_ARG_INFO(0, ycoord)
  697. ZEND_ARG_INFO(0, space)
  698. ZEND_ARG_INFO(0, tightness)
  699. ZEND_ARG_INFO(0, angle)
  700. ZEND_ARG_INFO(0, antialias)
  701. ZEND_END_ARG_INFO()
  702. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepsbbox, 0, 0, 3)
  703. ZEND_ARG_INFO(0, text)
  704. ZEND_ARG_INFO(0, font)
  705. ZEND_ARG_INFO(0, size)
  706. ZEND_ARG_INFO(0, space)
  707. ZEND_ARG_INFO(0, tightness)
  708. ZEND_ARG_INFO(0, angle)
  709. ZEND_END_ARG_INFO()
  710. #endif
  711. #ifdef HAVE_GD_WBMP
  712. ZEND_BEGIN_ARG_INFO_EX(arginfo_image2wbmp, 0, 0, 1)
  713. ZEND_ARG_INFO(0, im)
  714. ZEND_ARG_INFO(0, filename)
  715. ZEND_ARG_INFO(0, threshold)
  716. ZEND_END_ARG_INFO()
  717. #endif
  718. #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
  719. ZEND_BEGIN_ARG_INFO(arginfo_jpeg2wbmp, 0)
  720. ZEND_ARG_INFO(0, f_org)
  721. ZEND_ARG_INFO(0, f_dest)
  722. ZEND_ARG_INFO(0, d_height)
  723. ZEND_ARG_INFO(0, d_width)
  724. ZEND_ARG_INFO(0, d_threshold)
  725. ZEND_END_ARG_INFO()
  726. #endif
  727. #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
  728. ZEND_BEGIN_ARG_INFO(arginfo_png2wbmp, 0)
  729. ZEND_ARG_INFO(0, f_org)
  730. ZEND_ARG_INFO(0, f_dest)
  731. ZEND_ARG_INFO(0, d_height)
  732. ZEND_ARG_INFO(0, d_width)
  733. ZEND_ARG_INFO(0, d_threshold)
  734. ZEND_END_ARG_INFO()
  735. #endif
  736. ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefilter, 0, 0, 2)
  737. ZEND_ARG_INFO(0, im)
  738. ZEND_ARG_INFO(0, filtertype)
  739. ZEND_ARG_INFO(0, arg1)
  740. ZEND_ARG_INFO(0, arg2)
  741. ZEND_ARG_INFO(0, arg3)
  742. ZEND_ARG_INFO(0, arg4)
  743. ZEND_END_ARG_INFO()
  744. ZEND_BEGIN_ARG_INFO(arginfo_imageconvolution, 0)
  745. ZEND_ARG_INFO(0, im)
  746. ZEND_ARG_INFO(0, matrix3x3) /* ARRAY_INFO(0, matrix3x3, 0) */
  747. ZEND_ARG_INFO(0, div)
  748. ZEND_ARG_INFO(0, offset)
  749. ZEND_END_ARG_INFO()
  750. #ifdef HAVE_GD_BUNDLED
  751. ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0)
  752. ZEND_ARG_INFO(0, im)
  753. ZEND_ARG_INFO(0, on)
  754. ZEND_END_ARG_INFO()
  755. #endif
  756. /* }}} */
  757. /* {{{ gd_functions[]
  758. */
  759. const zend_function_entry gd_functions[] = {
  760. PHP_FE(gd_info, arginfo_gd_info)
  761. PHP_FE(imagearc, arginfo_imagearc)
  762. PHP_FE(imageellipse, arginfo_imageellipse)
  763. PHP_FE(imagechar, arginfo_imagechar)
  764. PHP_FE(imagecharup, arginfo_imagecharup)
  765. PHP_FE(imagecolorat, arginfo_imagecolorat)
  766. PHP_FE(imagecolorallocate, arginfo_imagecolorallocate)
  767. #if HAVE_LIBGD15
  768. PHP_FE(imagepalettecopy, arginfo_imagepalettecopy)
  769. PHP_FE(imagecreatefromstring, arginfo_imagecreatefromstring)
  770. #endif
  771. PHP_FE(imagecolorclosest, arginfo_imagecolorclosest)
  772. #if HAVE_COLORCLOSESTHWB
  773. PHP_FE(imagecolorclosesthwb, arginfo_imagecolorclosesthwb)
  774. #endif
  775. PHP_FE(imagecolordeallocate, arginfo_imagecolordeallocate)
  776. PHP_FE(imagecolorresolve, arginfo_imagecolorresolve)
  777. PHP_FE(imagecolorexact, arginfo_imagecolorexact)
  778. PHP_FE(imagecolorset, arginfo_imagecolorset)
  779. PHP_FE(imagecolortransparent, arginfo_imagecolortransparent)
  780. PHP_FE(imagecolorstotal, arginfo_imagecolorstotal)
  781. PHP_FE(imagecolorsforindex, arginfo_imagecolorsforindex)
  782. PHP_FE(imagecopy, arginfo_imagecopy)
  783. #if HAVE_LIBGD15
  784. PHP_FE(imagecopymerge, arginfo_imagecopymerge)
  785. PHP_FE(imagecopymergegray, arginfo_imagecopymergegray)
  786. #endif
  787. PHP_FE(imagecopyresized, arginfo_imagecopyresized)
  788. PHP_FE(imagecreate, arginfo_imagecreate)
  789. PHP_FE(imagecreatetruecolor, arginfo_imagecreatetruecolor)
  790. PHP_FE(imageistruecolor, arginfo_imageistruecolor)
  791. PHP_FE(imagetruecolortopalette, arginfo_imagetruecolortopalette)
  792. PHP_FE(imagesetthickness, arginfo_imagesetthickness)
  793. PHP_FE(imagefilledarc, arginfo_imagefilledarc)
  794. PHP_FE(imagefilledellipse, arginfo_imagefilledellipse)
  795. PHP_FE(imagealphablending, arginfo_imagealphablending)
  796. PHP_FE(imagesavealpha, arginfo_imagesavealpha)
  797. PHP_FE(imagecolorallocatealpha, arginfo_imagecolorallocatealpha)
  798. PHP_FE(imagecolorresolvealpha, arginfo_imagecolorresolvealpha)
  799. PHP_FE(imagecolorclosestalpha, arginfo_imagecolorclosestalpha)
  800. PHP_FE(imagecolorexactalpha, arginfo_imagecolorexactalpha)
  801. PHP_FE(imagecopyresampled, arginfo_imagecopyresampled)
  802. #ifdef PHP_WIN32
  803. PHP_FE(imagegrabwindow, arginfo_imagegrabwindow)
  804. PHP_FE(imagegrabscreen, arginfo_imagegrabscreen)
  805. #endif
  806. PHP_FE(imagerotate, arginfo_imagerotate)
  807. #ifdef HAVE_GD_BUNDLED
  808. PHP_FE(imageantialias, arginfo_imageantialias)
  809. #endif
  810. #if HAVE_GD_IMAGESETTILE
  811. PHP_FE(imagesettile, arginfo_imagesettile)
  812. #endif
  813. #if HAVE_GD_IMAGESETBRUSH
  814. PHP_FE(imagesetbrush, arginfo_imagesetbrush)
  815. #endif
  816. PHP_FE(imagesetstyle, arginfo_imagesetstyle)
  817. #ifdef HAVE_GD_PNG
  818. PHP_FE(imagecreatefrompng, arginfo_imagecreatefrompng)
  819. #endif
  820. #ifdef HAVE_GD_GIF_READ
  821. PHP_FE(imagecreatefromgif, arginfo_imagecreatefromgif)
  822. #endif
  823. #ifdef HAVE_GD_JPG
  824. PHP_FE(imagecreatefromjpeg, arginfo_imagecreatefromjpeg)
  825. #endif
  826. #ifdef HAVE_GD_WBMP
  827. PHP_FE(imagecreatefromwbmp, arginfo_imagecreatefromwbmp)
  828. #endif
  829. #ifdef HAVE_GD_XBM
  830. PHP_FE(imagecreatefromxbm, arginfo_imagecreatefromxbm)
  831. #endif
  832. #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
  833. PHP_FE(imagecreatefromxpm, arginfo_imagecreatefromxpm)
  834. #endif
  835. PHP_FE(imagecreatefromgd, arginfo_imagecreatefromgd)
  836. #ifdef HAVE_GD_GD2
  837. PHP_FE(imagecreatefromgd2, arginfo_imagecreatefromgd2)
  838. PHP_FE(imagecreatefromgd2part, arginfo_imagecreatefromgd2part)
  839. #endif
  840. #ifdef HAVE_GD_PNG
  841. PHP_FE(imagepng, arginfo_imagepng)
  842. #endif
  843. #ifdef HAVE_GD_GIF_CREATE
  844. PHP_FE(imagegif, arginfo_imagegif)
  845. #endif
  846. #ifdef HAVE_GD_JPG
  847. PHP_FE(imagejpeg, arginfo_imagejpeg)
  848. #endif
  849. #ifdef HAVE_GD_WBMP
  850. PHP_FE(imagewbmp, arginfo_imagewbmp)
  851. #endif
  852. PHP_FE(imagegd, arginfo_imagegd)
  853. #ifdef HAVE_GD_GD2
  854. PHP_FE(imagegd2, arginfo_imagegd2)
  855. #endif
  856. PHP_FE(imagedestroy, arginfo_imagedestroy)
  857. PHP_FE(imagegammacorrect, arginfo_imagegammacorrect)
  858. PHP_FE(imagefill, arginfo_imagefill)
  859. PHP_FE(imagefilledpolygon, arginfo_imagefilledpolygon)
  860. PHP_FE(imagefilledrectangle, arginfo_imagefilledrectangle)
  861. PHP_FE(imagefilltoborder, arginfo_imagefilltoborder)
  862. PHP_FE(imagefontwidth, arginfo_imagefontwidth)
  863. PHP_FE(imagefontheight, arginfo_imagefontheight)
  864. PHP_FE(imageinterlace, arginfo_imageinterlace)
  865. PHP_FE(imageline, arginfo_imageline)
  866. PHP_FE(imageloadfont, arginfo_imageloadfont)
  867. PHP_FE(imagepolygon, arginfo_imagepolygon)
  868. PHP_FE(imagerectangle, arginfo_imagerectangle)
  869. PHP_FE(imagesetpixel, arginfo_imagesetpixel)
  870. PHP_FE(imagestring, arginfo_imagestring)
  871. PHP_FE(imagestringup, arginfo_imagestringup)
  872. PHP_FE(imagesx, arginfo_imagesx)
  873. PHP_FE(imagesy, arginfo_imagesy)
  874. PHP_FE(imagedashedline, arginfo_imagedashedline)
  875. #ifdef ENABLE_GD_TTF
  876. PHP_FE(imagettfbbox, arginfo_imagettfbbox)
  877. PHP_FE(imagettftext, arginfo_imagettftext)
  878. #if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
  879. PHP_FE(imageftbbox, arginfo_imageftbbox)
  880. PHP_FE(imagefttext, arginfo_imagefttext)
  881. #endif
  882. #endif
  883. #ifdef HAVE_LIBT1
  884. PHP_FE(imagepsloadfont, arginfo_imagepsloadfont)
  885. /*
  886. PHP_FE(imagepscopyfont, arginfo_imagepscopyfont)
  887. */
  888. PHP_FE(imagepsfreefont, arginfo_imagepsfreefont)
  889. PHP_FE(imagepsencodefont, arginfo_imagepsencodefont)
  890. PHP_FE(imagepsextendfont, arginfo_imagepsextendfont)
  891. PHP_FE(imagepsslantfont, arginfo_imagepsslantfont)
  892. PHP_FE(imagepstext, arginfo_imagepstext)
  893. PHP_FE(imagepsbbox, arginfo_imagepsbbox)
  894. #endif
  895. PHP_FE(imagetypes, arginfo_imagetypes)
  896. #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
  897. PHP_FE(jpeg2wbmp, arginfo_jpeg2wbmp)
  898. #endif
  899. #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
  900. PHP_FE(png2wbmp, arginfo_png2wbmp)
  901. #endif
  902. #ifdef HAVE_GD_WBMP
  903. PHP_FE(image2wbmp, arginfo_image2wbmp)
  904. #endif
  905. #if HAVE_GD_BUNDLED
  906. PHP_FE(imagelayereffect, arginfo_imagelayereffect)
  907. PHP_FE(imagexbm, arginfo_imagexbm)
  908. #endif
  909. PHP_FE(imagecolormatch, arginfo_imagecolormatch)
  910. /* gd filters */
  911. PHP_FE(imagefilter, arginfo_imagefilter)
  912. PHP_FE(imageconvolution, arginfo_imageconvolution)
  913. {NULL, NULL, NULL}
  914. };
  915. /* }}} */
  916. zend_module_entry gd_module_entry = {
  917. STANDARD_MODULE_HEADER,
  918. "gd",
  919. gd_functions,
  920. PHP_MINIT(gd),
  921. #if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
  922. PHP_MSHUTDOWN(gd),
  923. #else
  924. NULL,
  925. #endif
  926. NULL,
  927. #if HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
  928. PHP_RSHUTDOWN(gd),
  929. #else
  930. NULL,
  931. #endif
  932. PHP_MINFO(gd),
  933. NO_VERSION_YET,
  934. STANDARD_MODULE_PROPERTIES
  935. };
  936. #ifdef COMPILE_DL_GD
  937. ZEND_GET_MODULE(gd)
  938. #endif
  939. /* {{{ PHP_INI_BEGIN */
  940. PHP_INI_BEGIN()
  941. PHP_INI_ENTRY("gd.jpeg_ignore_warning", "0", PHP_INI_ALL, NULL)
  942. PHP_INI_END()
  943. /* }}} */
  944. /* {{{ php_free_gd_image
  945. */
  946. static void php_free_gd_image(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  947. {
  948. gdImageDestroy((gdImagePtr) rsrc->ptr);
  949. }
  950. /* }}} */
  951. /* {{{ php_free_gd_font
  952. */
  953. static void php_free_gd_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  954. {
  955. gdFontPtr fp = (gdFontPtr) rsrc->ptr;
  956. if (fp->data) {
  957. efree(fp->data);
  958. }
  959. efree(fp);
  960. }
  961. /* }}} */
  962. /* {{{ PHP_MSHUTDOWN_FUNCTION
  963. */
  964. #if HAVE_LIBT1 || HAVE_GD_FONTMUTEX
  965. PHP_MSHUTDOWN_FUNCTION(gd)
  966. {
  967. #if HAVE_LIBT1
  968. T1_CloseLib();
  969. #endif
  970. #if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
  971. gdFontCacheMutexShutdown();
  972. #endif
  973. UNREGISTER_INI_ENTRIES();
  974. return SUCCESS;
  975. }
  976. #endif
  977. /* }}} */
  978. /* {{{ PHP_MINIT_FUNCTION
  979. */
  980. PHP_MINIT_FUNCTION(gd)
  981. {
  982. le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
  983. le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
  984. #if HAVE_GD_FONTMUTEX && HAVE_LIBFREETYPE
  985. gdFontCacheMutexSetup();
  986. #endif
  987. #if HAVE_LIBT1
  988. T1_SetBitmapPad(8);
  989. T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
  990. T1_SetLogLevel(T1LOG_DEBUG);
  991. le_ps_font = zend_register_list_destructors_ex(php_free_ps_font, NULL, "gd PS font", module_number);
  992. le_ps_enc = zend_register_list_destructors_ex(php_free_ps_enc, NULL, "gd PS encoding", module_number);
  993. #endif
  994. REGISTER_INI_ENTRIES();
  995. REGISTER_LONG_CONSTANT("IMG_GIF", 1, CONST_CS | CONST_PERSISTENT);
  996. REGISTER_LONG_CONSTANT("IMG_JPG", 2, CONST_CS | CONST_PERSISTENT);
  997. REGISTER_LONG_CONSTANT("IMG_JPEG", 2, CONST_CS | CONST_PERSISTENT);
  998. REGISTER_LONG_CONSTANT("IMG_PNG", 4, CONST_CS | CONST_PERSISTENT);
  999. REGISTER_LONG_CONSTANT("IMG_WBMP", 8, CONST_CS | CONST_PERSISTENT);
  1000. REGISTER_LONG_CONSTANT("IMG_XPM", 16, CONST_CS | CONST_PERSISTENT);
  1001. #ifdef gdTiled
  1002. /* special colours for gd */
  1003. REGISTER_LONG_CONSTANT("IMG_COLOR_TILED", gdTiled, CONST_CS | CONST_PERSISTENT);
  1004. REGISTER_LONG_CONSTANT("IMG_COLOR_STYLED", gdStyled, CONST_CS | CONST_PERSISTENT);
  1005. REGISTER_LONG_CONSTANT("IMG_COLOR_BRUSHED", gdBrushed, CONST_CS | CONST_PERSISTENT);
  1006. REGISTER_LONG_CONSTANT("IMG_COLOR_STYLEDBRUSHED", gdStyledBrushed, CONST_CS | CONST_PERSISTENT);
  1007. REGISTER_LONG_CONSTANT("IMG_COLOR_TRANSPARENT", gdTransparent, CONST_CS | CONST_PERSISTENT);
  1008. #endif
  1009. /* for imagefilledarc */
  1010. REGISTER_LONG_CONSTANT("IMG_ARC_ROUNDED", gdArc, CONST_CS | CONST_PERSISTENT);
  1011. REGISTER_LONG_CONSTANT("IMG_ARC_PIE", gdPie, CONST_CS | CONST_PERSISTENT);
  1012. REGISTER_LONG_CONSTANT("IMG_ARC_CHORD", gdChord, CONST_CS | CONST_PERSISTENT);
  1013. REGISTER_LONG_CONSTANT("IMG_ARC_NOFILL", gdNoFill, CONST_CS | CONST_PERSISTENT);
  1014. REGISTER_LONG_CONSTANT("IMG_ARC_EDGED", gdEdged, CONST_CS | CONST_PERSISTENT);
  1015. /* GD2 image format types */
  1016. #ifdef GD2_FMT_RAW
  1017. REGISTER_LONG_CONSTANT("IMG_GD2_RAW", GD2_FMT_RAW, CONST_CS | CONST_PERSISTENT);
  1018. #endif
  1019. #ifdef GD2_FMT_COMPRESSED
  1020. REGISTER_LONG_CONSTANT("IMG_GD2_COMPRESSED", GD2_FMT_COMPRESSED, CONST_CS | CONST_PERSISTENT);
  1021. #endif
  1022. #if HAVE_GD_BUNDLED
  1023. REGISTER_LONG_CONSTANT("IMG_EFFECT_REPLACE", gdEffectReplace, CONST_CS | CONST_PERSISTENT);
  1024. REGISTER_LONG_CONSTANT("IMG_EFFECT_ALPHABLEND", gdEffectAlphaBlend, CONST_CS | CONST_PERSISTENT);
  1025. REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT);
  1026. REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT);
  1027. REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT);
  1028. #else
  1029. REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
  1030. #endif
  1031. /* Section Filters */
  1032. REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT);
  1033. REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT);
  1034. REGISTER_LONG_CONSTANT("IMG_FILTER_BRIGHTNESS", IMAGE_FILTER_BRIGHTNESS, CONST_CS | CONST_PERSISTENT);
  1035. REGISTER_LONG_CONSTANT("IMG_FILTER_CONTRAST", IMAGE_FILTER_CONTRAST, CONST_CS | CONST_PERSISTENT);
  1036. REGISTER_LONG_CONSTANT("IMG_FILTER_COLORIZE", IMAGE_FILTER_COLORIZE, CONST_CS | CONST_PERSISTENT);
  1037. REGISTER_LONG_CONSTANT("IMG_FILTER_EDGEDETECT", IMAGE_FILTER_EDGEDETECT, CONST_CS | CONST_PERSISTENT);
  1038. REGISTER_LONG_CONSTANT("IMG_FILTER_GAUSSIAN_BLUR", IMAGE_FILTER_GAUSSIAN_BLUR, CONST_CS | CONST_PERSISTENT);
  1039. REGISTER_LONG_CONSTANT("IMG_FILTER_SELECTIVE_BLUR", IMAGE_FILTER_SELECTIVE_BLUR, CONST_CS | CONST_PERSISTENT);
  1040. REGISTER_LONG_CONSTANT("IMG_FILTER_EMBOSS", IMAGE_FILTER_EMBOSS, CONST_CS | CONST_PERSISTENT);
  1041. REGISTER_LONG_CONSTANT("IMG_FILTER_MEAN_REMOVAL", IMAGE_FILTER_MEAN_REMOVAL, CONST_CS | CONST_PERSISTENT);
  1042. REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);
  1043. REGISTER_LONG_CONSTANT("IMG_FILTER_PIXELATE", IMAGE_FILTER_PIXELATE, CONST_CS | CONST_PERSISTENT);
  1044. /* End Section Filters */
  1045. #ifdef GD_VERSION_STRING
  1046. REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
  1047. #endif
  1048. #if defined(GD_MAJOR_VERSION) && defined(GD_MINOR_VERSION) && defined(GD_RELEASE_VERSION) && defined(GD_EXTRA_VERSION)
  1049. REGISTER_LONG_CONSTANT("GD_MAJOR_VERSION", GD_MAJOR_VERSION, CONST_CS | CONST_PERSISTENT);
  1050. REGISTER_LONG_CONSTANT("GD_MINOR_VERSION", GD_MINOR_VERSION, CONST_CS | CONST_PERSISTENT);
  1051. REGISTER_LONG_CONSTANT("GD_RELEASE_VERSION", GD_RELEASE_VERSION, CONST_CS | CONST_PERSISTENT);
  1052. REGISTER_STRING_CONSTANT("GD_EXTRA_VERSION", GD_EXTRA_VERSION, CONST_CS | CONST_PERSISTENT);
  1053. #endif
  1054. #ifdef HAVE_GD_PNG
  1055. /*
  1056. * cannot include #include "png.h"
  1057. * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h with some additional fixup.
  1058. * as error, use the values for now...
  1059. */
  1060. REGISTER_LONG_CONSTANT("PNG_NO_FILTER", 0x00, CONST_CS | CONST_PERSISTENT);
  1061. REGISTER_LONG_CONSTANT("PNG_FILTER_NONE", 0x08, CONST_CS | CONST_PERSISTENT);
  1062. REGISTER_LONG_CONSTANT("PNG_FILTER_SUB", 0x10, CONST_CS | CONST_PERSISTENT);
  1063. REGISTER_LONG_CONSTANT("PNG_FILTER_UP", 0x20, CONST_CS | CONST_PERSISTENT);
  1064. REGISTER_LONG_CONSTANT("PNG_FILTER_AVG", 0x40, CONST_CS | CONST_PERSISTENT);
  1065. REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH", 0x80, CONST_CS | CONST_PERSISTENT);
  1066. REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS", 0x08 | 0x10 | 0x20 | 0x40 | 0x80, CONST_CS | CONST_PERSISTENT);
  1067. #endif
  1068. return SUCCESS;
  1069. }
  1070. /* }}} */
  1071. /* {{{ PHP_RSHUTDOWN_FUNCTION
  1072. */
  1073. #if HAVE_GD_STRINGFT && (HAVE_LIBFREETYPE && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE))
  1074. PHP_RSHUTDOWN_FUNCTION(gd)
  1075. {
  1076. #if HAVE_GD_FONTCACHESHUTDOWN
  1077. gdFontCacheShutdown();
  1078. #else
  1079. gdFreeFontCache();
  1080. #endif
  1081. return SUCCESS;
  1082. }
  1083. #endif
  1084. /* }}} */
  1085. #if HAVE_GD_BUNDLED
  1086. #define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)"
  1087. #else
  1088. #define PHP_GD_VERSION_STRING "2.0"
  1089. #endif
  1090. /* {{{ PHP_MINFO_FUNCTION
  1091. */
  1092. PHP_MINFO_FUNCTION(gd)
  1093. {
  1094. php_info_print_table_start();
  1095. php_info_print_table_row(2, "GD Support", "enabled");
  1096. /* need to use a PHPAPI function here because it is external module in windows */
  1097. php_info_print_table_row(2, "GD Version", PHP_GD_VERSION_STRING);
  1098. #ifdef ENABLE_GD_TTF
  1099. php_info_print_table_row(2, "FreeType Support", "enabled");
  1100. #if HAVE_LIBFREETYPE
  1101. php_info_print_table_row(2, "FreeType Linkage", "with freetype");
  1102. {
  1103. char tmp[256];
  1104. #ifdef FREETYPE_PATCH
  1105. snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
  1106. #elif defined(FREETYPE_MAJOR)
  1107. snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
  1108. #else
  1109. snprintf(tmp, sizeof(tmp), "1.x");
  1110. #endif
  1111. php_info_print_table_row(2, "FreeType Version", tmp);
  1112. }
  1113. #else
  1114. php_info_print_table_row(2, "FreeType Linkage", "with unknown library");
  1115. #endif
  1116. #endif
  1117. #ifdef HAVE_LIBT1
  1118. php_info_print_table_row(2, "T1Lib Support", "enabled");
  1119. #endif
  1120. /* this next part is stupid ... if I knew better, I'd put them all on one row (cmv) */
  1121. #ifdef HAVE_GD_GIF_READ
  1122. php_info_print_table_row(2, "GIF Read Support", "enabled");
  1123. #endif
  1124. #ifdef HAVE_GD_GIF_CREATE
  1125. php_info_print_table_row(2, "GIF Create Support", "enabled");
  1126. #endif
  1127. #ifdef HAVE_GD_JPG
  1128. {
  1129. char tmp[12];
  1130. snprintf(tmp, sizeof(tmp), "%s", gdJpegGetVersionString());
  1131. php_info_print_table_row(2, "JPEG Support", "enabled");
  1132. php_info_print_table_row(2, "libJPEG Version", tmp);
  1133. }
  1134. #endif
  1135. #ifdef HAVE_GD_PNG
  1136. php_info_print_table_row(2, "PNG Support", "enabled");
  1137. php_info_print_table_row(2, "libPNG Version", gdPngGetVersionString());
  1138. #endif
  1139. #ifdef HAVE_GD_WBMP
  1140. php_info_print_table_row(2, "WBMP Support", "enabled");
  1141. #endif
  1142. #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
  1143. php_info_print_table_row(2, "XPM Support", "enabled");
  1144. #endif
  1145. #ifdef HAVE_GD_XBM
  1146. php_info_print_table_row(2, "XBM Support", "enabled");
  1147. #endif
  1148. #if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
  1149. php_info_print_table_row(2, "JIS-mapped Japanese Font Support", "enabled");
  1150. #endif
  1151. php_info_print_table_end();
  1152. DISPLAY_INI_ENTRIES();
  1153. }
  1154. /* }}} */
  1155. /* {{{ proto array gd_info()
  1156. */
  1157. PHP_FUNCTION(gd_info)
  1158. {
  1159. if (zend_parse_parameters_none() == FAILURE) {
  1160. RETURN_FALSE;
  1161. }
  1162. array_init(return_value);
  1163. add_assoc_string(return_value, "GD Version", PHP_GD_VERSION_STRING, 1);
  1164. #ifdef ENABLE_GD_TTF
  1165. add_assoc_bool(return_value, "FreeType Support", 1);
  1166. #if HAVE_LIBFREETYPE
  1167. add_assoc_string(return_value, "FreeType Linkage", "with freetype", 1);
  1168. #else
  1169. add_assoc_string(return_value, "FreeType Linkage", "with unknown library", 1);
  1170. #endif
  1171. #else
  1172. add_assoc_bool(return_value, "FreeType Support", 0);
  1173. #endif
  1174. #ifdef HAVE_LIBT1
  1175. add_assoc_bool(return_value, "T1Lib Support", 1);
  1176. #else
  1177. add_assoc_bool(return_value, "T1Lib Support", 0);
  1178. #endif
  1179. #ifdef HAVE_GD_GIF_READ
  1180. add_assoc_bool(return_value, "GIF Read Support", 1);
  1181. #else
  1182. add_assoc_bool(return_value, "GIF Read Support", 0);
  1183. #endif
  1184. #ifdef HAVE_GD_GIF_CREATE
  1185. add_assoc_bool(return_value, "GIF Create Support", 1);
  1186. #else
  1187. add_assoc_bool(return_value, "GIF Create Support", 0);
  1188. #endif
  1189. #ifdef HAVE_GD_JPG
  1190. add_assoc_bool(return_value, "JPEG Support", 1);
  1191. #else
  1192. add_assoc_bool(return_value, "JPEG Support", 0);
  1193. #endif
  1194. #ifdef HAVE_GD_PNG
  1195. add_assoc_bool(return_value, "PNG Support", 1);
  1196. #else
  1197. add_assoc_bool(return_value, "PNG Support", 0);
  1198. #endif
  1199. #ifdef HAVE_GD_WBMP
  1200. add_assoc_bool(return_value, "WBMP Support", 1);
  1201. #else
  1202. add_assoc_bool(return_value, "WBMP Support", 0);
  1203. #endif
  1204. #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
  1205. add_assoc_bool(return_value, "XPM Support", 1);
  1206. #else
  1207. add_assoc_bool(return_value, "XPM Support", 0);
  1208. #endif
  1209. #ifdef HAVE_GD_XBM
  1210. add_assoc_bool(return_value, "XBM Support", 1);
  1211. #else
  1212. add_assoc_bool(return_value, "XBM Support", 0);
  1213. #endif
  1214. #if defined(USE_GD_JISX0208) && defined(HAVE_GD_BUNDLED)
  1215. add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 1);
  1216. #else
  1217. add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 0);
  1218. #endif
  1219. }
  1220. /* }}} */
  1221. /* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */
  1222. PHP_GD_API int phpi_get_le_gd(void)
  1223. {
  1224. return le_gd;
  1225. }
  1226. /* }}} */
  1227. #ifndef HAVE_GDIMAGECOLORRESOLVE
  1228. /* {{{ gdImageColorResolve
  1229. */
  1230. /********************************************************************/
  1231. /* gdImageColorResolve is a replacement for the old fragment: */
  1232. /* */
  1233. /* if ((color=gdImageColorExact(im,R,G,B)) < 0) */
  1234. /* if ((color=gdImageColorAllocate(im,R,G,B)) < 0) */
  1235. /* color=gdImageColorClosest(im,R,G,B); */
  1236. /* */
  1237. /* in a single function */
  1238. int gdImageColorResolve(gdImagePtr im, int r, int g, int b)
  1239. {
  1240. int c;
  1241. int ct = -1;
  1242. int op = -1;
  1243. long rd, gd, bd, dist;
  1244. long mindist = 3*255*255; /* init to max poss dist */
  1245. for (c = 0; c < im->colorsTotal; c++) {
  1246. if (im->open[c]) {
  1247. op = c; /* Save open slot */
  1248. continue; /* Color not in use */
  1249. }
  1250. rd = (long) (im->red [c] - r);
  1251. gd = (long) (im->green[c] - g);
  1252. bd = (long) (im->blue [c] - b);
  1253. dist = rd * rd + gd * gd + bd * bd;
  1254. if (dist < mindist) {
  1255. if (dist == 0) {
  1256. return c; /* Return exact match color */
  1257. }
  1258. mindist = dist;
  1259. ct = c;
  1260. }
  1261. }
  1262. /* no exact match. We now know closest, but first try to allocate exact */
  1263. if (op == -1) {
  1264. op = im->colorsTotal;
  1265. if (op == gdMaxColors) { /* No room for more colors */
  1266. return ct; /* Return closest available color */
  1267. }
  1268. im->colorsTotal++;
  1269. }
  1270. im->red [op] = r;
  1271. im->green[op] = g;
  1272. im->blue [op] = b;
  1273. im->open [op] = 0;
  1274. return op; /* Return newly allocated color */
  1275. }
  1276. /* }}} */
  1277. #endif
  1278. #define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
  1279. /* {{{ proto int imageloadfont(string filename)
  1280. Load a new font */
  1281. PHP_FUNCTION(imageloadfont)
  1282. {
  1283. char *file;
  1284. int file_name, hdr_size = sizeof(gdFont) - sizeof(char *);
  1285. int ind, body_size, n = 0, b, i, body_size_check;
  1286. gdFontPtr font;
  1287. php_stream *stream;
  1288. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_name) == FAILURE) {
  1289. return;
  1290. }
  1291. stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
  1292. if (stream == NULL) {
  1293. RETURN_FALSE;
  1294. }
  1295. /* Only supports a architecture-dependent binary dump format
  1296. * at the moment.
  1297. * The file format is like this on machines with 32-byte integers:
  1298. *
  1299. * byte 0-3: (int) number of characters in the font
  1300. * byte 4-7: (int) value of first character in the font (often 32, space)
  1301. * byte 8-11: (int) pixel width of each character
  1302. * byte 12-15: (int) pixel height of each character
  1303. * bytes 16-: (char) array with character data, one byte per pixel
  1304. * in each character, for a total of
  1305. * (nchars*width*height) bytes.
  1306. */
  1307. font = (gdFontPtr) emalloc(sizeof(gdFont));
  1308. b = 0;
  1309. while (b < hdr_size && (n = php_stream_read(stream, (char*)&font[b], hdr_size - b))) {
  1310. b += n;
  1311. }
  1312. if (!n) {
  1313. efree(font);
  1314. if (php_stream_eof(stream)) {
  1315. php_error_docref(NULL TSRMLS_CC, E_WARNING, "End of file while reading header");
  1316. } else {
  1317. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading header");
  1318. }
  1319. php_stream_close(stream);
  1320. RETURN_FALSE;
  1321. }
  1322. i = php_stream_tell(stream);
  1323. php_stream_seek(stream, 0, SEEK_END);
  1324. body_size_check = php_stream_tell(stream) - hdr_size;
  1325. php_stream_seek(stream, i, SEEK_SET);
  1326. body_size = font->w * font->h * font->nchars;
  1327. if (body_size != body_size_check) {
  1328. font->w = FLIPWORD(font->w);
  1329. font->h = FLIPWORD(font->h);
  1330. font->nchars = FLIPWORD(font->nchars);
  1331. body_size = font->w * font->h * font->nchars;
  1332. }
  1333. if (overflow2(font->nchars, font->h)) {
  1334. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font, invalid font header");
  1335. efree(font);
  1336. php_stream_close(stream);
  1337. RETURN_FALSE;
  1338. }
  1339. if (overflow2(font->nchars * font->h, font->w )) {
  1340. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font, invalid font header");
  1341. efree(font);
  1342. php_stream_close(stream);
  1343. RETURN_FALSE;
  1344. }
  1345. if (body_size != body_size_check) {
  1346. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading font");
  1347. efree(font);
  1348. php_stream_close(stream);
  1349. RETURN_FALSE;
  1350. }
  1351. font->data = emalloc(body_size);
  1352. b = 0;
  1353. while (b < body_size && (n = php_stream_read(stream, &font->data[b], body_size - b))) {
  1354. b += n;
  1355. }
  1356. if (!n) {
  1357. efree(font->data);
  1358. efree(font);
  1359. if (php_stream_eof(stream)) {
  1360. php_error_docref(NULL TSRMLS_CC, E_WARNING, "End of file while reading body");
  1361. } else {
  1362. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading body");
  1363. }
  1364. php_stream_close(stream);
  1365. RETURN_FALSE;
  1366. }
  1367. php_stream_close(stream);
  1368. /* Adding 5 to the font index so we will never have font indices
  1369. * that overlap with the old fonts (with indices 1-5). The first
  1370. * list index given out is always 1.
  1371. */
  1372. ind = 5 + zend_list_insert(font, le_gd_font);
  1373. RETURN_LONG(ind);
  1374. }
  1375. /* }}} */
  1376. /* {{{ proto bool imagesetstyle(resource im, array styles)
  1377. Set the line drawing styles for use with imageline and IMG_COLOR_STYLED. */
  1378. PHP_FUNCTION(imagesetstyle)
  1379. {
  1380. zval *IM, *styles;
  1381. gdImagePtr im;
  1382. int * stylearr;
  1383. int index;
  1384. HashPosition pos;
  1385. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &IM, &styles) == FAILURE) {
  1386. return;
  1387. }
  1388. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1389. /* copy the style values in the stylearr */
  1390. stylearr = safe_emalloc(sizeof(int), zend_hash_num_elements(HASH_OF(styles)), 0);
  1391. zend_hash_internal_pointer_reset_ex(HASH_OF(styles), &pos);
  1392. for (index = 0;; zend_hash_move_forward_ex(HASH_OF(styles), &pos)) {
  1393. zval ** item;
  1394. if (zend_hash_get_current_data_ex(HASH_OF(styles), (void **) &item, &pos) == FAILURE) {
  1395. break;
  1396. }
  1397. convert_to_long_ex(item);
  1398. stylearr[index++] = Z_LVAL_PP(item);
  1399. }
  1400. gdImageSetStyle(im, stylearr, index);
  1401. efree(stylearr);
  1402. RETURN_TRUE;
  1403. }
  1404. /* }}} */
  1405. /* {{{ proto resource imagecreatetruecolor(int x_size, int y_size)
  1406. Create a new true color image */
  1407. PHP_FUNCTION(imagecreatetruecolor)
  1408. {
  1409. long x_size, y_size;
  1410. gdImagePtr im;
  1411. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x_size, &y_size) == FAILURE) {
  1412. return;
  1413. }
  1414. if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX) {
  1415. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
  1416. RETURN_FALSE;
  1417. }
  1418. im = gdImageCreateTrueColor(x_size, y_size);
  1419. if (!im) {
  1420. RETURN_FALSE;
  1421. }
  1422. ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
  1423. }
  1424. /* }}} */
  1425. /* {{{ proto bool imageistruecolor(resource im)
  1426. return true if the image uses truecolor */
  1427. PHP_FUNCTION(imageistruecolor)
  1428. {
  1429. zval *IM;
  1430. gdImagePtr im;
  1431. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
  1432. return;
  1433. }
  1434. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1435. RETURN_BOOL(im->trueColor);
  1436. }
  1437. /* }}} */
  1438. /* {{{ proto void imagetruecolortopalette(resource im, bool ditherFlag, int colorsWanted)
  1439. Convert a true colour image to a palette based image with a number of colours, optionally using dithering. */
  1440. PHP_FUNCTION(imagetruecolortopalette)
  1441. {
  1442. zval *IM;
  1443. zend_bool dither;
  1444. long ncolors;
  1445. gdImagePtr im;
  1446. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rbl", &IM, &dither, &ncolors) == FAILURE) {
  1447. return;
  1448. }
  1449. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1450. if (ncolors <= 0) {
  1451. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of colors has to be greater than zero");
  1452. RETURN_FALSE;
  1453. }
  1454. gdImageTrueColorToPalette(im, dither, ncolors);
  1455. RETURN_TRUE;
  1456. }
  1457. /* }}} */
  1458. /* {{{ proto bool imagecolormatch(resource im1, resource im2)
  1459. Makes the colors of the palette version of an image more closely match the true color version */
  1460. PHP_FUNCTION(imagecolormatch)
  1461. {
  1462. zval *IM1, *IM2;
  1463. gdImagePtr im1, im2;
  1464. int result;
  1465. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM1, &IM2) == FAILURE) {
  1466. return;
  1467. }
  1468. ZEND_FETCH_RESOURCE(im1, gdImagePtr, &IM1, -1, "Image", le_gd);
  1469. ZEND_FETCH_RESOURCE(im2, gdImagePtr, &IM2, -1, "Image", le_gd);
  1470. result = gdImageColorMatch(im1, im2);
  1471. switch (result) {
  1472. case -1:
  1473. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 must be TrueColor" );
  1474. RETURN_FALSE;
  1475. break;
  1476. case -2:
  1477. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must be Palette" );
  1478. RETURN_FALSE;
  1479. break;
  1480. case -3:
  1481. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image1 and Image2 must be the same size" );
  1482. RETURN_FALSE;
  1483. break;
  1484. case -4:
  1485. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Image2 must have at least one color" );
  1486. RETURN_FALSE;
  1487. break;
  1488. }
  1489. RETURN_TRUE;
  1490. }
  1491. /* }}} */
  1492. /* {{{ proto bool imagesetthickness(resource im, int thickness)
  1493. Set line thickness for drawing lines, ellipses, rectangles, polygons etc. */
  1494. PHP_FUNCTION(imagesetthickness)
  1495. {
  1496. zval *IM;
  1497. long thick;
  1498. gdImagePtr im;
  1499. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &thick) == FAILURE) {
  1500. return;
  1501. }
  1502. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1503. gdImageSetThickness(im, thick);
  1504. RETURN_TRUE;
  1505. }
  1506. /* }}} */
  1507. /* {{{ proto bool imagefilledellipse(resource im, int cx, int cy, int w, int h, int color)
  1508. Draw an ellipse */
  1509. PHP_FUNCTION(imagefilledellipse)
  1510. {
  1511. zval *IM;
  1512. long cx, cy, w, h, color;
  1513. gdImagePtr im;
  1514. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
  1515. return;
  1516. }
  1517. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1518. gdImageFilledEllipse(im, cx, cy, w, h, color);
  1519. RETURN_TRUE;
  1520. }
  1521. /* }}} */
  1522. /* {{{ proto bool imagefilledarc(resource im, int cx, int cy, int w, int h, int s, int e, int col, int style)
  1523. Draw a filled partial ellipse */
  1524. PHP_FUNCTION(imagefilledarc)
  1525. {
  1526. zval *IM;
  1527. long cx, cy, w, h, ST, E, col, style;
  1528. gdImagePtr im;
  1529. int e, st;
  1530. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) {
  1531. return;
  1532. }
  1533. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1534. e = E;
  1535. if (e < 0) {
  1536. e %= 360;
  1537. }
  1538. st = ST;
  1539. if (st < 0) {
  1540. st %= 360;
  1541. }
  1542. gdImageFilledArc(im, cx, cy, w, h, st, e, col, style);
  1543. RETURN_TRUE;
  1544. }
  1545. /* }}} */
  1546. /* {{{ proto bool imagealphablending(resource im, bool on)
  1547. Turn alpha blending mode on or off for the given image */
  1548. PHP_FUNCTION(imagealphablending)
  1549. {
  1550. zval *IM;
  1551. zend_bool blend;
  1552. gdImagePtr im;
  1553. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &blend) == FAILURE) {
  1554. return;
  1555. }
  1556. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1557. gdImageAlphaBlending(im, blend);
  1558. RETURN_TRUE;
  1559. }
  1560. /* }}} */
  1561. /* {{{ proto bool imagesavealpha(resource im, bool on)
  1562. Include alpha channel to a saved image */
  1563. PHP_FUNCTION(imagesavealpha)
  1564. {
  1565. zval *IM;
  1566. zend_bool save;
  1567. gdImagePtr im;
  1568. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &save) == FAILURE) {
  1569. return;
  1570. }
  1571. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1572. gdImageSaveAlpha(im, save);
  1573. RETURN_TRUE;
  1574. }
  1575. /* }}} */
  1576. #if HAVE_GD_BUNDLED
  1577. /* {{{ proto bool imagelayereffect(resource im, int effect)
  1578. Set the alpha blending flag to use the bundled libgd layering effects */
  1579. PHP_FUNCTION(imagelayereffect)
  1580. {
  1581. zval *IM;
  1582. long effect;
  1583. gdImagePtr im;
  1584. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &effect) == FAILURE) {
  1585. return;
  1586. }
  1587. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1588. gdImageAlphaBlending(im, effect);
  1589. RETURN_TRUE;
  1590. }
  1591. /* }}} */
  1592. #endif
  1593. /* {{{ proto int imagecolorallocatealpha(resource im, int red, int green, int blue, int alpha)
  1594. Allocate a color with an alpha level. Works for true color and palette based images */
  1595. PHP_FUNCTION(imagecolorallocatealpha)
  1596. {
  1597. zval *IM;
  1598. long red, green, blue, alpha;
  1599. gdImagePtr im;
  1600. int ct = (-1);
  1601. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
  1602. RETURN_FALSE;
  1603. }
  1604. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1605. ct = gdImageColorAllocateAlpha(im, red, green, blue, alpha);
  1606. if (ct < 0) {
  1607. RETURN_FALSE;
  1608. }
  1609. RETURN_LONG((long)ct);
  1610. }
  1611. /* }}} */
  1612. /* {{{ proto int imagecolorresolvealpha(resource im, int red, int green, int blue, int alpha)
  1613. Resolve/Allocate a colour with an alpha level. Works for true colour and palette based images */
  1614. PHP_FUNCTION(imagecolorresolvealpha)
  1615. {
  1616. zval *IM;
  1617. long red, green, blue, alpha;
  1618. gdImagePtr im;
  1619. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
  1620. return;
  1621. }
  1622. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1623. RETURN_LONG(gdImageColorResolveAlpha(im, red, green, blue, alpha));
  1624. }
  1625. /* }}} */
  1626. /* {{{ proto int imagecolorclosestalpha(resource im, int red, int green, int blue, int alpha)
  1627. Find the closest matching colour with alpha transparency */
  1628. PHP_FUNCTION(imagecolorclosestalpha)
  1629. {
  1630. zval *IM;
  1631. long red, green, blue, alpha;
  1632. gdImagePtr im;
  1633. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
  1634. return;
  1635. }
  1636. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1637. RETURN_LONG(gdImageColorClosestAlpha(im, red, green, blue, alpha));
  1638. }
  1639. /* }}} */
  1640. /* {{{ proto int imagecolorexactalpha(resource im, int red, int green, int blue, int alpha)
  1641. Find exact match for colour with transparency */
  1642. PHP_FUNCTION(imagecolorexactalpha)
  1643. {
  1644. zval *IM;
  1645. long red, green, blue, alpha;
  1646. gdImagePtr im;
  1647. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) {
  1648. return;
  1649. }
  1650. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1651. RETURN_LONG(gdImageColorExactAlpha(im, red, green, blue, alpha));
  1652. }
  1653. /* }}} */
  1654. /* {{{ proto bool imagecopyresampled(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h)
  1655. Copy and resize part of an image using resampling to help ensure clarity */
  1656. PHP_FUNCTION(imagecopyresampled)
  1657. {
  1658. zval *SIM, *DIM;
  1659. long SX, SY, SW, SH, DX, DY, DW, DH;
  1660. gdImagePtr im_dst, im_src;
  1661. int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
  1662. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) {
  1663. return;
  1664. }
  1665. ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
  1666. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  1667. srcX = SX;
  1668. srcY = SY;
  1669. srcH = SH;
  1670. srcW = SW;
  1671. dstX = DX;
  1672. dstY = DY;
  1673. dstH = DH;
  1674. dstW = DW;
  1675. gdImageCopyResampled(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
  1676. RETURN_TRUE;
  1677. }
  1678. /* }}} */
  1679. #ifdef PHP_WIN32
  1680. /* {{{ proto resource imagegrabwindow(int window_handle [, int client_area])
  1681. Grab a window or its client area using a windows handle (HWND property in COM instance) */
  1682. PHP_FUNCTION(imagegrabwindow)
  1683. {
  1684. HWND window;
  1685. long client_area = 0;
  1686. RECT rc = {0};
  1687. RECT rc_win = {0};
  1688. int Width, Height;
  1689. HDC hdc;
  1690. HDC memDC;
  1691. HBITMAP memBM;
  1692. HBITMAP hOld;
  1693. HINSTANCE handle;
  1694. long lwindow_handle;
  1695. typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
  1696. tPrintWindow pPrintWindow = 0;
  1697. gdImagePtr im;
  1698. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &lwindow_handle, &client_area) == FAILURE) {
  1699. RETURN_FALSE;
  1700. }
  1701. window = (HWND) lwindow_handle;
  1702. if (!IsWindow(window)) {
  1703. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Invalid window handle");
  1704. RETURN_FALSE;
  1705. }
  1706. hdc = GetDC(0);
  1707. if (client_area) {
  1708. GetClientRect(window, &rc);
  1709. Width = rc.right;
  1710. Height = rc.bottom;
  1711. } else {
  1712. GetWindowRect(window, &rc);
  1713. Width = rc.right - rc.left;
  1714. Height = rc.bottom - rc.top;
  1715. }
  1716. Width = (Width/4)*4;
  1717. memDC = CreateCompatibleDC(hdc);
  1718. memBM = CreateCompatibleBitmap(hdc, Width, Height);
  1719. hOld = (HBITMAP) SelectObject (memDC, memBM);
  1720. handle = LoadLibrary("User32.dll");
  1721. if ( handle == 0 ) {
  1722. goto clean;
  1723. }
  1724. pPrintWindow = (tPrintWindow) GetProcAddress(handle, "PrintWindow");
  1725. if ( pPrintWindow ) {
  1726. pPrintWindow(window, memDC, (UINT) client_area);
  1727. } else {
  1728. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows API too old");
  1729. goto clean;
  1730. }
  1731. FreeLibrary(handle);
  1732. im = gdImageCreateTrueColor(Width, Height);
  1733. if (im) {
  1734. int x,y;
  1735. for (y=0; y <= Height; y++) {
  1736. for (x=0; x <= Width; x++) {
  1737. int c = GetPixel(memDC, x,y);
  1738. gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
  1739. }
  1740. }
  1741. }
  1742. clean:
  1743. SelectObject(memDC,hOld);
  1744. DeleteObject(memBM);
  1745. DeleteDC(memDC);
  1746. ReleaseDC( 0, hdc );
  1747. if (!im) {
  1748. RETURN_FALSE;
  1749. } else {
  1750. ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
  1751. }
  1752. }
  1753. /* }}} */
  1754. /* {{{ proto resource imagegrabscreen()
  1755. Grab a screenshot */
  1756. PHP_FUNCTION(imagegrabscreen)
  1757. {
  1758. HWND window = GetDesktopWindow();
  1759. RECT rc = {0};
  1760. int Width, Height;
  1761. HDC hdc;
  1762. HDC memDC;
  1763. HBITMAP memBM;
  1764. HBITMAP hOld;
  1765. typedef BOOL (WINAPI *tPrintWindow)(HWND, HDC,UINT);
  1766. tPrintWindow pPrintWindow = 0;
  1767. gdImagePtr im;
  1768. hdc = GetDC(0);
  1769. if (zend_parse_parameters_none() == FAILURE) {
  1770. return;
  1771. }
  1772. if (!hdc) {
  1773. RETURN_FALSE;
  1774. }
  1775. GetWindowRect(window, &rc);
  1776. Width = rc.right - rc.left;
  1777. Height = rc.bottom - rc.top;
  1778. Width = (Width/4)*4;
  1779. memDC = CreateCompatibleDC(hdc);
  1780. memBM = CreateCompatibleBitmap(hdc, Width, Height);
  1781. hOld = (HBITMAP) SelectObject (memDC, memBM);
  1782. BitBlt( memDC, 0, 0, Width, Height , hdc, rc.left, rc.top , SRCCOPY );
  1783. im = gdImageCreateTrueColor(Width, Height);
  1784. if (im) {
  1785. int x,y;
  1786. for (y=0; y <= Height; y++) {
  1787. for (x=0; x <= Width; x++) {
  1788. int c = GetPixel(memDC, x,y);
  1789. gdImageSetPixel(im, x, y, gdTrueColor(GetRValue(c), GetGValue(c), GetBValue(c)));
  1790. }
  1791. }
  1792. }
  1793. SelectObject(memDC,hOld);
  1794. DeleteObject(memBM);
  1795. DeleteDC(memDC);
  1796. ReleaseDC( 0, hdc );
  1797. if (!im) {
  1798. RETURN_FALSE;
  1799. } else {
  1800. ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
  1801. }
  1802. }
  1803. /* }}} */
  1804. #endif /* PHP_WIN32 */
  1805. /* {{{ proto resource imagerotate(resource src_im, float angle, int bgdcolor [, int ignoretransparent])
  1806. Rotate an image using a custom angle */
  1807. PHP_FUNCTION(imagerotate)
  1808. {
  1809. zval *SIM;
  1810. gdImagePtr im_dst, im_src;
  1811. double degrees;
  1812. long color;
  1813. long ignoretransparent = 0;
  1814. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdl|l", &SIM, &degrees, &color, &ignoretransparent) == FAILURE) {
  1815. RETURN_FALSE;
  1816. }
  1817. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  1818. im_dst = gdImageRotate(im_src, degrees, color, ignoretransparent);
  1819. if (im_dst != NULL) {
  1820. ZEND_REGISTER_RESOURCE(return_value, im_dst, le_gd);
  1821. } else {
  1822. RETURN_FALSE;
  1823. }
  1824. }
  1825. /* }}} */
  1826. #if HAVE_GD_IMAGESETTILE
  1827. /* {{{ proto bool imagesettile(resource image, resource tile)
  1828. Set the tile image to $tile when filling $image with the "IMG_COLOR_TILED" color */
  1829. PHP_FUNCTION(imagesettile)
  1830. {
  1831. zval *IM, *TILE;
  1832. gdImagePtr im, tile;
  1833. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM, &TILE) == FAILURE) {
  1834. return;
  1835. }
  1836. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1837. ZEND_FETCH_RESOURCE(tile, gdImagePtr, &TILE, -1, "Image", le_gd);
  1838. gdImageSetTile(im, tile);
  1839. RETURN_TRUE;
  1840. }
  1841. /* }}} */
  1842. #endif
  1843. #if HAVE_GD_IMAGESETBRUSH
  1844. /* {{{ proto bool imagesetbrush(resource image, resource brush)
  1845. Set the brush image to $brush when filling $image with the "IMG_COLOR_BRUSHED" color */
  1846. PHP_FUNCTION(imagesetbrush)
  1847. {
  1848. zval *IM, *TILE;
  1849. gdImagePtr im, tile;
  1850. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &IM, &TILE) == FAILURE) {
  1851. return;
  1852. }
  1853. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  1854. ZEND_FETCH_RESOURCE(tile, gdImagePtr, &TILE, -1, "Image", le_gd);
  1855. gdImageSetBrush(im, tile);
  1856. RETURN_TRUE;
  1857. }
  1858. /* }}} */
  1859. #endif
  1860. /* {{{ proto resource imagecreate(int x_size, int y_size)
  1861. Create a new image */
  1862. PHP_FUNCTION(imagecreate)
  1863. {
  1864. long x_size, y_size;
  1865. gdImagePtr im;
  1866. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &x_size, &y_size) == FAILURE) {
  1867. return;
  1868. }
  1869. if (x_size <= 0 || y_size <= 0 || x_size >= INT_MAX || y_size >= INT_MAX) {
  1870. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
  1871. RETURN_FALSE;
  1872. }
  1873. im = gdImageCreate(x_size, y_size);
  1874. if (!im) {
  1875. RETURN_FALSE;
  1876. }
  1877. ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
  1878. }
  1879. /* }}} */
  1880. /* {{{ proto int imagetypes(void)
  1881. Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM */
  1882. PHP_FUNCTION(imagetypes)
  1883. {
  1884. int ret=0;
  1885. #ifdef HAVE_GD_GIF_CREATE
  1886. ret = 1;
  1887. #endif
  1888. #ifdef HAVE_GD_JPG
  1889. ret |= 2;
  1890. #endif
  1891. #ifdef HAVE_GD_PNG
  1892. ret |= 4;
  1893. #endif
  1894. #ifdef HAVE_GD_WBMP
  1895. ret |= 8;
  1896. #endif
  1897. #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
  1898. ret |= 16;
  1899. #endif
  1900. if (zend_parse_parameters_none() == FAILURE) {
  1901. return;
  1902. }
  1903. RETURN_LONG(ret);
  1904. }
  1905. /* }}} */
  1906. /* {{{ _php_image_type
  1907. */
  1908. static const char php_sig_gd2[3] = {'g', 'd', '2'};
  1909. static int _php_image_type (char data[8])
  1910. {
  1911. #ifdef HAVE_LIBGD15
  1912. /* Based on ext/standard/image.c */
  1913. if (data == NULL) {
  1914. return -1;
  1915. }
  1916. if (!memcmp(data, php_sig_gd2, 3)) {
  1917. return PHP_GDIMG_TYPE_GD2;
  1918. } else if (!memcmp(data, php_sig_jpg, 3)) {
  1919. return PHP_GDIMG_TYPE_JPG;
  1920. } else if (!memcmp(data, php_sig_png, 3)) {
  1921. if (!memcmp(data, php_sig_png, 8)) {
  1922. return PHP_GDIMG_TYPE_PNG;
  1923. }
  1924. } else if (!memcmp(data, php_sig_gif, 3)) {
  1925. return PHP_GDIMG_TYPE_GIF;
  1926. }
  1927. #ifdef HAVE_GD_WBMP
  1928. else {
  1929. gdIOCtx *io_ctx;
  1930. io_ctx = gdNewDynamicCtxEx(8, data, 0);
  1931. if (io_ctx) {
  1932. if (getmbi((int(*)(void *)) gdGetC, io_ctx) == 0 && skipheader((int(*)(void *)) gdGetC, io_ctx) == 0 ) {
  1933. #if HAVE_LIBGD204
  1934. io_ctx->gd_free(io_ctx);
  1935. #else
  1936. io_ctx->free(io_ctx);
  1937. #endif
  1938. return PHP_GDIMG_TYPE_WBM;
  1939. } else {
  1940. #if HAVE_LIBGD204
  1941. io_ctx->gd_free(io_ctx);
  1942. #else
  1943. io_ctx->free(io_ctx);
  1944. #endif
  1945. }
  1946. }
  1947. }
  1948. #endif
  1949. return -1;
  1950. #endif
  1951. }
  1952. /* }}} */
  1953. #ifdef HAVE_LIBGD15
  1954. /* {{{ _php_image_create_from_string
  1955. */
  1956. gdImagePtr _php_image_create_from_string(zval **data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC)
  1957. {
  1958. gdImagePtr im;
  1959. gdIOCtx *io_ctx;
  1960. io_ctx = gdNewDynamicCtxEx(Z_STRLEN_PP(data), Z_STRVAL_PP(data), 0);
  1961. if (!io_ctx) {
  1962. return NULL;
  1963. }
  1964. im = (*ioctx_func_p)(io_ctx);
  1965. if (!im) {
  1966. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed data is not in '%s' format", tn);
  1967. #if HAVE_LIBGD204
  1968. io_ctx->gd_free(io_ctx);
  1969. #else
  1970. io_ctx->free(io_ctx);
  1971. #endif
  1972. return NULL;
  1973. }
  1974. #if HAVE_LIBGD204
  1975. io_ctx->gd_free(io_ctx);
  1976. #else
  1977. io_ctx->free(io_ctx);
  1978. #endif
  1979. return im;
  1980. }
  1981. /* }}} */
  1982. /* {{{ proto resource imagecreatefromstring(string image)
  1983. Create a new image from the image stream in the string */
  1984. PHP_FUNCTION(imagecreatefromstring)
  1985. {
  1986. zval **data;
  1987. gdImagePtr im;
  1988. int imtype;
  1989. char sig[8];
  1990. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &data) == FAILURE) {
  1991. return;
  1992. }
  1993. convert_to_string_ex(data);
  1994. if (Z_STRLEN_PP(data) < 8) {
  1995. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty string or invalid image");
  1996. RETURN_FALSE;
  1997. }
  1998. memcpy(sig, Z_STRVAL_PP(data), 8);
  1999. imtype = _php_image_type(sig);
  2000. switch (imtype) {
  2001. case PHP_GDIMG_TYPE_JPG:
  2002. #ifdef HAVE_GD_JPG
  2003. im = _php_image_create_from_string(data, "JPEG", gdImageCreateFromJpegCtx TSRMLS_CC);
  2004. #else
  2005. php_error_docref(NULL TSRMLS_CC, E_WARNING, "No JPEG support in this PHP build");
  2006. RETURN_FALSE;
  2007. #endif
  2008. break;
  2009. case PHP_GDIMG_TYPE_PNG:
  2010. #ifdef HAVE_GD_PNG
  2011. im = _php_image_create_from_string(data, "PNG", gdImageCreateFromPngCtx TSRMLS_CC);
  2012. #else
  2013. php_error_docref(NULL TSRMLS_CC, E_WARNING, "No PNG support in this PHP build");
  2014. RETURN_FALSE;
  2015. #endif
  2016. break;
  2017. case PHP_GDIMG_TYPE_GIF:
  2018. #ifdef HAVE_GD_GIF_READ
  2019. im = _php_image_create_from_string(data, "GIF", gdImageCreateFromGifCtx TSRMLS_CC);
  2020. #else
  2021. php_error_docref(NULL TSRMLS_CC, E_WARNING, "No GIF support in this PHP build");
  2022. RETURN_FALSE;
  2023. #endif
  2024. break;
  2025. case PHP_GDIMG_TYPE_WBM:
  2026. #ifdef HAVE_GD_WBMP
  2027. im = _php_image_create_from_string(data, "WBMP", gdImageCreateFromWBMPCtx TSRMLS_CC);
  2028. #else
  2029. php_error_docref(NULL TSRMLS_CC, E_WARNING, "No WBMP support in this PHP build");
  2030. RETURN_FALSE;
  2031. #endif
  2032. break;
  2033. case PHP_GDIMG_TYPE_GD2:
  2034. #ifdef HAVE_GD_GD2
  2035. im = _php_image_create_from_string(data, "GD2", gdImageCreateFromGd2Ctx TSRMLS_CC);
  2036. #else
  2037. php_error_docref(NULL TSRMLS_CC, E_WARNING, "No GD2 support in this PHP build");
  2038. RETURN_FALSE;
  2039. #endif
  2040. break;
  2041. default:
  2042. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Data is not in a recognized format");
  2043. RETURN_FALSE;
  2044. }
  2045. if (!im) {
  2046. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't create GD Image Stream out of Data");
  2047. RETURN_FALSE;
  2048. }
  2049. ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
  2050. }
  2051. /* }}} */
  2052. #endif
  2053. /* {{{ _php_image_create_from
  2054. */
  2055. static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)())
  2056. {
  2057. char *file;
  2058. int file_len;
  2059. long srcx, srcy, width, height;
  2060. gdImagePtr im = NULL;
  2061. php_stream *stream;
  2062. FILE * fp = NULL;
  2063. #ifdef HAVE_GD_JPG
  2064. long ignore_warning;
  2065. #endif
  2066. if (image_type == PHP_GDIMG_TYPE_GD2PART) {
  2067. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sllll", &file, &file_len, &srcx, &srcy, &width, &height) == FAILURE) {
  2068. return;
  2069. }
  2070. if (width < 1 || height < 1) {
  2071. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero width or height not allowed");
  2072. RETURN_FALSE;
  2073. }
  2074. } else {
  2075. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
  2076. return;
  2077. }
  2078. }
  2079. stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
  2080. if (stream == NULL) {
  2081. RETURN_FALSE;
  2082. }
  2083. #ifndef USE_GD_IOCTX
  2084. ioctx_func_p = NULL; /* don't allow sockets without IOCtx */
  2085. #endif
  2086. /* try and avoid allocating a FILE* if the stream is not naturally a FILE* */
  2087. if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) {
  2088. if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS)) {
  2089. goto out_err;
  2090. }
  2091. } else if (ioctx_func_p) {
  2092. #ifdef USE_GD_IOCTX
  2093. /* we can create an io context */
  2094. gdIOCtx* io_ctx;
  2095. size_t buff_size;
  2096. char *buff;
  2097. /* needs to be malloc (persistent) - GD will free() it later */
  2098. buff_size = php_stream_copy_to_mem(stream, &buff, PHP_STREAM_COPY_ALL, 1);
  2099. if (!buff_size) {
  2100. php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot read image data");
  2101. goto out_err;
  2102. }
  2103. io_ctx = gdNewDynamicCtxEx(buff_size, buff, 0);
  2104. if (!io_ctx) {
  2105. pefree(buff, 1);
  2106. php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
  2107. goto out_err;
  2108. }
  2109. if (image_type == PHP_GDIMG_TYPE_GD2PART) {
  2110. im = (*ioctx_func_p)(io_ctx, srcx, srcy, width, height);
  2111. } else {
  2112. im = (*ioctx_func_p)(io_ctx);
  2113. }
  2114. #if HAVE_LIBGD204
  2115. io_ctx->gd_free(io_ctx);
  2116. #else
  2117. io_ctx->free(io_ctx);
  2118. #endif
  2119. pefree(buff, 1);
  2120. #endif
  2121. }
  2122. else {
  2123. /* try and force the stream to be FILE* */
  2124. if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD, (void **) &fp, REPORT_ERRORS)) {
  2125. goto out_err;
  2126. }
  2127. }
  2128. if (!im && fp) {
  2129. switch (image_type) {
  2130. case PHP_GDIMG_TYPE_GD2PART:
  2131. im = (*func_p)(fp, srcx, srcy, width, height);
  2132. break;
  2133. #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
  2134. case PHP_GDIMG_TYPE_XPM:
  2135. im = gdImageCreateFromXpm(file);
  2136. break;
  2137. #endif
  2138. #ifdef HAVE_GD_JPG
  2139. case PHP_GDIMG_TYPE_JPG:
  2140. ignore_warning = INI_INT("gd.jpeg_ignore_warning");
  2141. #ifdef HAVE_GD_BUNDLED
  2142. im = gdImageCreateFromJpeg(fp, ignore_warning);
  2143. #else
  2144. im = gdImageCreateFromJpeg(fp);
  2145. #endif
  2146. break;
  2147. #endif
  2148. default:
  2149. im = (*func_p)(fp);
  2150. break;
  2151. }
  2152. fflush(fp);
  2153. }
  2154. if (im) {
  2155. ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
  2156. php_stream_close(stream);
  2157. return;
  2158. }
  2159. php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid %s file", file, tn);
  2160. out_err:
  2161. php_stream_close(stream);
  2162. RETURN_FALSE;
  2163. }
  2164. /* }}} */
  2165. #ifdef HAVE_GD_GIF_READ
  2166. /* {{{ proto resource imagecreatefromgif(string filename)
  2167. Create a new image from GIF file or URL */
  2168. PHP_FUNCTION(imagecreatefromgif)
  2169. {
  2170. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageCreateFromGif, gdImageCreateFromGifCtx);
  2171. }
  2172. /* }}} */
  2173. #endif /* HAVE_GD_GIF_READ */
  2174. #ifdef HAVE_GD_JPG
  2175. /* {{{ proto resource imagecreatefromjpeg(string filename)
  2176. Create a new image from JPEG file or URL */
  2177. PHP_FUNCTION(imagecreatefromjpeg)
  2178. {
  2179. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageCreateFromJpeg, gdImageCreateFromJpegCtx);
  2180. }
  2181. /* }}} */
  2182. #endif /* HAVE_GD_JPG */
  2183. #ifdef HAVE_GD_PNG
  2184. /* {{{ proto resource imagecreatefrompng(string filename)
  2185. Create a new image from PNG file or URL */
  2186. PHP_FUNCTION(imagecreatefrompng)
  2187. {
  2188. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImageCreateFromPng, gdImageCreateFromPngCtx);
  2189. }
  2190. /* }}} */
  2191. #endif /* HAVE_GD_PNG */
  2192. #ifdef HAVE_GD_XBM
  2193. /* {{{ proto resource imagecreatefromxbm(string filename)
  2194. Create a new image from XBM file or URL */
  2195. PHP_FUNCTION(imagecreatefromxbm)
  2196. {
  2197. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageCreateFromXbm, NULL);
  2198. }
  2199. /* }}} */
  2200. #endif /* HAVE_GD_XBM */
  2201. #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED)
  2202. /* {{{ proto resource imagecreatefromxpm(string filename)
  2203. Create a new image from XPM file or URL */
  2204. PHP_FUNCTION(imagecreatefromxpm)
  2205. {
  2206. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XPM, "XPM", gdImageCreateFromXpm, NULL);
  2207. }
  2208. /* }}} */
  2209. #endif
  2210. #ifdef HAVE_GD_WBMP
  2211. /* {{{ proto resource imagecreatefromwbmp(string filename)
  2212. Create a new image from WBMP file or URL */
  2213. PHP_FUNCTION(imagecreatefromwbmp)
  2214. {
  2215. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageCreateFromWBMP, gdImageCreateFromWBMPCtx);
  2216. }
  2217. /* }}} */
  2218. #endif /* HAVE_GD_WBMP */
  2219. /* {{{ proto resource imagecreatefromgd(string filename)
  2220. Create a new image from GD file or URL */
  2221. PHP_FUNCTION(imagecreatefromgd)
  2222. {
  2223. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageCreateFromGd, gdImageCreateFromGdCtx);
  2224. }
  2225. /* }}} */
  2226. #ifdef HAVE_GD_GD2
  2227. /* {{{ proto resource imagecreatefromgd2(string filename)
  2228. Create a new image from GD2 file or URL */
  2229. PHP_FUNCTION(imagecreatefromgd2)
  2230. {
  2231. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageCreateFromGd2, gdImageCreateFromGd2Ctx);
  2232. }
  2233. /* }}} */
  2234. /* {{{ proto resource imagecreatefromgd2part(string filename, int srcX, int srcY, int width, int height)
  2235. Create a new image from a given part of GD2 file or URL */
  2236. PHP_FUNCTION(imagecreatefromgd2part)
  2237. {
  2238. _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2PART, "GD2", gdImageCreateFromGd2Part, gdImageCreateFromGd2PartCtx);
  2239. }
  2240. /* }}} */
  2241. #endif /* HAVE_GD_GD2 */
  2242. /* {{{ _php_image_output
  2243. */
  2244. static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
  2245. {
  2246. zval *imgind;
  2247. char *file = NULL;
  2248. long quality = 0, type = 0;
  2249. gdImagePtr im;
  2250. char *fn = NULL;
  2251. FILE *fp;
  2252. int file_len = 0, argc = ZEND_NUM_ARGS();
  2253. int q = -1, i, t = 1;
  2254. /* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
  2255. /* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */
  2256. /* The quality parameter for gd2 stands for chunk size */
  2257. if (zend_parse_parameters(argc TSRMLS_CC, "r|sll", &imgind, &file, &file_len, &quality, &type) == FAILURE) {
  2258. return;
  2259. }
  2260. ZEND_FETCH_RESOURCE(im, gdImagePtr, &imgind, -1, "Image", le_gd);
  2261. if (argc > 1) {
  2262. fn = file;
  2263. if (argc == 3) {
  2264. q = quality;
  2265. }
  2266. if (argc == 4) {
  2267. t = type;
  2268. }
  2269. }
  2270. if (argc >= 2 && file_len) {
  2271. if (strlen(file) != file_len) {
  2272. RETURN_FALSE;
  2273. }
  2274. PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
  2275. fp = VCWD_FOPEN(fn, "wb");
  2276. if (!fp) {
  2277. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
  2278. RETURN_FALSE;
  2279. }
  2280. switch (image_type) {
  2281. #ifdef HAVE_GD_WBMP
  2282. case PHP_GDIMG_CONVERT_WBM:
  2283. if (q == -1) {
  2284. q = 0;
  2285. } else if (q < 0 || q > 255) {
  2286. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
  2287. q = 0;
  2288. }
  2289. gdImageWBMP(im, q, fp);
  2290. break;
  2291. #endif
  2292. case PHP_GDIMG_TYPE_JPG:
  2293. (*func_p)(im, fp, q);
  2294. break;
  2295. case PHP_GDIMG_TYPE_WBM:
  2296. for (i = 0; i < gdImageColorsTotal(im); i++) {
  2297. if (gdImageRed(im, i) == 0) break;
  2298. }
  2299. (*func_p)(im, i, fp);
  2300. break;
  2301. case PHP_GDIMG_TYPE_GD:
  2302. if (im->trueColor){
  2303. gdImageTrueColorToPalette(im,1,256);
  2304. }
  2305. (*func_p)(im, fp);
  2306. break;
  2307. #ifdef HAVE_GD_GD2
  2308. case PHP_GDIMG_TYPE_GD2:
  2309. if (q == -1) {
  2310. q = 128;
  2311. }
  2312. (*func_p)(im, fp, q, t);
  2313. break;
  2314. #endif
  2315. default:
  2316. if (q == -1) {
  2317. q = 128;
  2318. }
  2319. (*func_p)(im, fp, q, t);
  2320. break;
  2321. }
  2322. fflush(fp);
  2323. fclose(fp);
  2324. } else {
  2325. int b;
  2326. FILE *tmp;
  2327. char buf[4096];
  2328. char *path;
  2329. tmp = php_open_temporary_file(NULL, NULL, &path TSRMLS_CC);
  2330. if (tmp == NULL) {
  2331. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open temporary file");
  2332. RETURN_FALSE;
  2333. }
  2334. switch (image_type) {
  2335. #ifdef HAVE_GD_WBMP
  2336. case PHP_GDIMG_CONVERT_WBM:
  2337. if (q == -1) {
  2338. q = 0;
  2339. } else if (q < 0 || q > 255) {
  2340. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
  2341. q = 0;
  2342. }
  2343. gdImageWBMP(im, q, tmp);
  2344. break;
  2345. #endif
  2346. case PHP_GDIMG_TYPE_JPG:
  2347. (*func_p)(im, tmp, q);
  2348. break;
  2349. case PHP_GDIMG_TYPE_WBM:
  2350. for (i = 0; i < gdImageColorsTotal(im); i++) {
  2351. if (gdImageRed(im, i) == 0) {
  2352. break;
  2353. }
  2354. }
  2355. (*func_p)(im, q, tmp);
  2356. break;
  2357. case PHP_GDIMG_TYPE_GD:
  2358. if (im->trueColor) {
  2359. gdImageTrueColorToPalette(im,1,256);
  2360. }
  2361. (*func_p)(im, tmp);
  2362. break;
  2363. #ifdef HAVE_GD_GD2
  2364. case PHP_GDIMG_TYPE_GD2:
  2365. if (q == -1) {
  2366. q = 128;
  2367. }
  2368. (*func_p)(im, tmp, q, t);
  2369. break;
  2370. #endif
  2371. default:
  2372. (*func_p)(im, tmp);
  2373. break;
  2374. }
  2375. fseek(tmp, 0, SEEK_SET);
  2376. #if APACHE && defined(CHARSET_EBCDIC)
  2377. /* XXX this is unlikely to work any more thies@thieso.net */
  2378. /* This is a binary file already: avoid EBCDIC->ASCII conversion */
  2379. ap_bsetflag(php3_rqst->connection->client, B_EBCDIC2ASCII, 0);
  2380. #endif
  2381. while ((b = fread(buf, 1, sizeof(buf), tmp)) > 0) {
  2382. php_write(buf, b TSRMLS_CC);
  2383. }
  2384. fclose(tmp);
  2385. VCWD_UNLINK((const char *)path); /* make sure that the temporary file is removed */
  2386. efree(path);
  2387. }
  2388. RETURN_TRUE;
  2389. }
  2390. /* }}} */
  2391. /* {{{ proto int imagexbm(int im, string filename [, int foreground])
  2392. Output XBM image to browser or file */
  2393. #if HAVE_GD_BUNDLED
  2394. PHP_FUNCTION(imagexbm)
  2395. {
  2396. _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
  2397. }
  2398. #endif
  2399. /* }}} */
  2400. #ifdef HAVE_GD_GIF_CREATE
  2401. /* {{{ proto bool imagegif(resource im [, string filename])
  2402. Output GIF image to browser or file */
  2403. PHP_FUNCTION(imagegif)
  2404. {
  2405. #ifdef HAVE_GD_GIF_CTX
  2406. _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGifCtx);
  2407. #else
  2408. _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGif);
  2409. #endif
  2410. }
  2411. /* }}} */
  2412. #endif /* HAVE_GD_GIF_CREATE */
  2413. #ifdef HAVE_GD_PNG
  2414. /* {{{ proto bool imagepng(resource im [, string filename])
  2415. Output PNG image to browser or file */
  2416. PHP_FUNCTION(imagepng)
  2417. {
  2418. #ifdef USE_GD_IOCTX
  2419. _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx);
  2420. #else
  2421. _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
  2422. #endif
  2423. }
  2424. /* }}} */
  2425. #endif /* HAVE_GD_PNG */
  2426. #ifdef HAVE_GD_JPG
  2427. /* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]])
  2428. Output JPEG image to browser or file */
  2429. PHP_FUNCTION(imagejpeg)
  2430. {
  2431. #ifdef USE_GD_IOCTX
  2432. _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpegCtx);
  2433. #else
  2434. _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpeg);
  2435. #endif
  2436. }
  2437. /* }}} */
  2438. #endif /* HAVE_GD_JPG */
  2439. #ifdef HAVE_GD_WBMP
  2440. /* {{{ proto bool imagewbmp(resource im [, string filename, [, int foreground]])
  2441. Output WBMP image to browser or file */
  2442. PHP_FUNCTION(imagewbmp)
  2443. {
  2444. #ifdef USE_GD_IOCTX
  2445. _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMPCtx);
  2446. #else
  2447. _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMP);
  2448. #endif
  2449. }
  2450. /* }}} */
  2451. #endif /* HAVE_GD_WBMP */
  2452. /* {{{ proto bool imagegd(resource im [, string filename])
  2453. Output GD image to browser or file */
  2454. PHP_FUNCTION(imagegd)
  2455. {
  2456. _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD, "GD", gdImageGd);
  2457. }
  2458. /* }}} */
  2459. #ifdef HAVE_GD_GD2
  2460. /* {{{ proto bool imagegd2(resource im [, string filename, [, int chunk_size, [, int type]]])
  2461. Output GD2 image to browser or file */
  2462. PHP_FUNCTION(imagegd2)
  2463. {
  2464. _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2", gdImageGd2);
  2465. }
  2466. /* }}} */
  2467. #endif /* HAVE_GD_GD2 */
  2468. /* {{{ proto bool imagedestroy(resource im)
  2469. Destroy an image */
  2470. PHP_FUNCTION(imagedestroy)
  2471. {
  2472. zval *IM;
  2473. gdImagePtr im;
  2474. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
  2475. return;
  2476. }
  2477. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2478. zend_list_delete(Z_LVAL_P(IM));
  2479. RETURN_TRUE;
  2480. }
  2481. /* }}} */
  2482. /* {{{ proto int imagecolorallocate(resource im, int red, int green, int blue)
  2483. Allocate a color for an image */
  2484. PHP_FUNCTION(imagecolorallocate)
  2485. {
  2486. zval *IM;
  2487. long red, green, blue;
  2488. gdImagePtr im;
  2489. int ct = (-1);
  2490. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
  2491. return;
  2492. }
  2493. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2494. ct = gdImageColorAllocate(im, red, green, blue);
  2495. if (ct < 0) {
  2496. RETURN_FALSE;
  2497. }
  2498. RETURN_LONG(ct);
  2499. }
  2500. /* }}} */
  2501. #if HAVE_LIBGD15
  2502. /* {{{ proto void imagepalettecopy(resource dst, resource src)
  2503. Copy the palette from the src image onto the dst image */
  2504. PHP_FUNCTION(imagepalettecopy)
  2505. {
  2506. zval *dstim, *srcim;
  2507. gdImagePtr dst, src;
  2508. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr", &dstim, &srcim) == FAILURE) {
  2509. return;
  2510. }
  2511. ZEND_FETCH_RESOURCE(dst, gdImagePtr, &dstim, -1, "Image", le_gd);
  2512. ZEND_FETCH_RESOURCE(src, gdImagePtr, &srcim, -1, "Image", le_gd);
  2513. gdImagePaletteCopy(dst, src);
  2514. }
  2515. /* }}} */
  2516. #endif
  2517. /* {{{ proto int imagecolorat(resource im, int x, int y)
  2518. Get the index of the color of a pixel */
  2519. PHP_FUNCTION(imagecolorat)
  2520. {
  2521. zval *IM;
  2522. long x, y;
  2523. gdImagePtr im;
  2524. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &IM, &x, &y) == FAILURE) {
  2525. return;
  2526. }
  2527. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2528. if (gdImageTrueColor(im)) {
  2529. if (im->tpixels && gdImageBoundsSafe(im, x, y)) {
  2530. RETURN_LONG(gdImageTrueColorPixel(im, x, y));
  2531. } else {
  2532. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", x, y);
  2533. RETURN_FALSE;
  2534. }
  2535. } else {
  2536. if (im->pixels && gdImageBoundsSafe(im, x, y)) {
  2537. RETURN_LONG(im->pixels[y][x]);
  2538. } else {
  2539. php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%ld,%ld is out of bounds", x, y);
  2540. RETURN_FALSE;
  2541. }
  2542. }
  2543. }
  2544. /* }}} */
  2545. /* {{{ proto int imagecolorclosest(resource im, int red, int green, int blue)
  2546. Get the index of the closest color to the specified color */
  2547. PHP_FUNCTION(imagecolorclosest)
  2548. {
  2549. zval *IM;
  2550. long red, green, blue;
  2551. gdImagePtr im;
  2552. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
  2553. return;
  2554. }
  2555. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2556. RETURN_LONG(gdImageColorClosest(im, red, green, blue));
  2557. }
  2558. /* }}} */
  2559. #if HAVE_COLORCLOSESTHWB
  2560. /* {{{ proto int imagecolorclosesthwb(resource im, int red, int green, int blue)
  2561. Get the index of the color which has the hue, white and blackness nearest to the given color */
  2562. PHP_FUNCTION(imagecolorclosesthwb)
  2563. {
  2564. zval *IM;
  2565. long red, green, blue;
  2566. gdImagePtr im;
  2567. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
  2568. return;
  2569. }
  2570. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2571. RETURN_LONG(gdImageColorClosestHWB(im, red, green, blue));
  2572. }
  2573. /* }}} */
  2574. #endif
  2575. /* {{{ proto bool imagecolordeallocate(resource im, int index)
  2576. De-allocate a color for an image */
  2577. PHP_FUNCTION(imagecolordeallocate)
  2578. {
  2579. zval *IM;
  2580. long index;
  2581. int col;
  2582. gdImagePtr im;
  2583. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &index) == FAILURE) {
  2584. return;
  2585. }
  2586. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2587. /* We can return right away for a truecolor image as deallocating colours is meaningless here */
  2588. if (gdImageTrueColor(im)) {
  2589. RETURN_TRUE;
  2590. }
  2591. col = index;
  2592. if (col >= 0 && col < gdImageColorsTotal(im)) {
  2593. gdImageColorDeallocate(im, col);
  2594. RETURN_TRUE;
  2595. } else {
  2596. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color index %d out of range", col);
  2597. RETURN_FALSE;
  2598. }
  2599. }
  2600. /* }}} */
  2601. /* {{{ proto int imagecolorresolve(resource im, int red, int green, int blue)
  2602. Get the index of the specified color or its closest possible alternative */
  2603. PHP_FUNCTION(imagecolorresolve)
  2604. {
  2605. zval *IM;
  2606. long red, green, blue;
  2607. gdImagePtr im;
  2608. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
  2609. return;
  2610. }
  2611. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2612. RETURN_LONG(gdImageColorResolve(im, red, green, blue));
  2613. }
  2614. /* }}} */
  2615. /* {{{ proto int imagecolorexact(resource im, int red, int green, int blue)
  2616. Get the index of the specified color */
  2617. PHP_FUNCTION(imagecolorexact)
  2618. {
  2619. zval *IM;
  2620. long red, green, blue;
  2621. gdImagePtr im;
  2622. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &red, &green, &blue) == FAILURE) {
  2623. return;
  2624. }
  2625. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2626. RETURN_LONG(gdImageColorExact(im, red, green, blue));
  2627. }
  2628. /* }}} */
  2629. /* {{{ proto void imagecolorset(resource im, int col, int red, int green, int blue)
  2630. Set the color for the specified palette index */
  2631. PHP_FUNCTION(imagecolorset)
  2632. {
  2633. zval *IM;
  2634. long color, red, green, blue;
  2635. int col;
  2636. gdImagePtr im;
  2637. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &color, &red, &green, &blue) == FAILURE) {
  2638. return;
  2639. }
  2640. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2641. col = color;
  2642. if (col >= 0 && col < gdImageColorsTotal(im)) {
  2643. im->red[col] = red;
  2644. im->green[col] = green;
  2645. im->blue[col] = blue;
  2646. } else {
  2647. RETURN_FALSE;
  2648. }
  2649. }
  2650. /* }}} */
  2651. /* {{{ proto array imagecolorsforindex(resource im, int col)
  2652. Get the colors for an index */
  2653. PHP_FUNCTION(imagecolorsforindex)
  2654. {
  2655. zval *IM;
  2656. long index;
  2657. int col;
  2658. gdImagePtr im;
  2659. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &IM, &index) == FAILURE) {
  2660. return;
  2661. }
  2662. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2663. col = index;
  2664. if ((col >= 0 && gdImageTrueColor(im)) || (!gdImageTrueColor(im) && col >= 0 && col < gdImageColorsTotal(im))) {
  2665. array_init(return_value);
  2666. add_assoc_long(return_value,"red", gdImageRed(im,col));
  2667. add_assoc_long(return_value,"green", gdImageGreen(im,col));
  2668. add_assoc_long(return_value,"blue", gdImageBlue(im,col));
  2669. add_assoc_long(return_value,"alpha", gdImageAlpha(im,col));
  2670. } else {
  2671. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Color index %d out of range", col);
  2672. RETURN_FALSE;
  2673. }
  2674. }
  2675. /* }}} */
  2676. /* {{{ proto bool imagegammacorrect(resource im, float inputgamma, float outputgamma)
  2677. Apply a gamma correction to a GD image */
  2678. PHP_FUNCTION(imagegammacorrect)
  2679. {
  2680. zval *IM;
  2681. gdImagePtr im;
  2682. int i;
  2683. double input, output;
  2684. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rdd", &IM, &input, &output) == FAILURE) {
  2685. return;
  2686. }
  2687. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2688. if (gdImageTrueColor(im)) {
  2689. int x, y, c;
  2690. for (y = 0; y < gdImageSY(im); y++) {
  2691. for (x = 0; x < gdImageSX(im); x++) {
  2692. c = gdImageGetPixel(im, x, y);
  2693. gdImageSetPixel(im, x, y,
  2694. gdTrueColor(
  2695. (int) ((pow((pow((gdTrueColorGetRed(c) / 255.0), input)), 1.0 / output) * 255) + .5),
  2696. (int) ((pow((pow((gdTrueColorGetGreen(c) / 255.0), input)), 1.0 / output) * 255) + .5),
  2697. (int) ((pow((pow((gdTrueColorGetBlue(c) / 255.0), input)), 1.0 / output) * 255) + .5)
  2698. )
  2699. );
  2700. }
  2701. }
  2702. RETURN_TRUE;
  2703. }
  2704. for (i = 0; i < gdImageColorsTotal(im); i++) {
  2705. im->red[i] = (int)((pow((pow((im->red[i] / 255.0), input)), 1.0 / output) * 255) + .5);
  2706. im->green[i] = (int)((pow((pow((im->green[i] / 255.0), input)), 1.0 / output) * 255) + .5);
  2707. im->blue[i] = (int)((pow((pow((im->blue[i] / 255.0), input)), 1.0 / output) * 255) + .5);
  2708. }
  2709. RETURN_TRUE;
  2710. }
  2711. /* }}} */
  2712. /* {{{ proto bool imagesetpixel(resource im, int x, int y, int col)
  2713. Set a single pixel */
  2714. PHP_FUNCTION(imagesetpixel)
  2715. {
  2716. zval *IM;
  2717. long x, y, col;
  2718. gdImagePtr im;
  2719. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &x, &y, &col) == FAILURE) {
  2720. return;
  2721. }
  2722. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2723. gdImageSetPixel(im, x, y, col);
  2724. RETURN_TRUE;
  2725. }
  2726. /* }}} */
  2727. /* {{{ proto bool imageline(resource im, int x1, int y1, int x2, int y2, int col)
  2728. Draw a line */
  2729. PHP_FUNCTION(imageline)
  2730. {
  2731. zval *IM;
  2732. long x1, y1, x2, y2, col;
  2733. gdImagePtr im;
  2734. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
  2735. return;
  2736. }
  2737. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2738. #ifdef HAVE_GD_BUNDLED
  2739. if (im->antialias) {
  2740. gdImageAALine(im, x1, y1, x2, y2, col);
  2741. } else
  2742. #endif
  2743. {
  2744. gdImageLine(im, x1, y1, x2, y2, col);
  2745. }
  2746. RETURN_TRUE;
  2747. }
  2748. /* }}} */
  2749. /* {{{ proto bool imagedashedline(resource im, int x1, int y1, int x2, int y2, int col)
  2750. Draw a dashed line */
  2751. PHP_FUNCTION(imagedashedline)
  2752. {
  2753. zval *IM;
  2754. long x1, y1, x2, y2, col;
  2755. gdImagePtr im;
  2756. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
  2757. return;
  2758. }
  2759. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2760. gdImageDashedLine(im, x1, y1, x2, y2, col);
  2761. RETURN_TRUE;
  2762. }
  2763. /* }}} */
  2764. /* {{{ proto bool imagerectangle(resource im, int x1, int y1, int x2, int y2, int col)
  2765. Draw a rectangle */
  2766. PHP_FUNCTION(imagerectangle)
  2767. {
  2768. zval *IM;
  2769. long x1, y1, x2, y2, col;
  2770. gdImagePtr im;
  2771. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
  2772. return;
  2773. }
  2774. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2775. gdImageRectangle(im, x1, y1, x2, y2, col);
  2776. RETURN_TRUE;
  2777. }
  2778. /* }}} */
  2779. /* {{{ proto bool imagefilledrectangle(resource im, int x1, int y1, int x2, int y2, int col)
  2780. Draw a filled rectangle */
  2781. PHP_FUNCTION(imagefilledrectangle)
  2782. {
  2783. zval *IM;
  2784. long x1, y1, x2, y2, col;
  2785. gdImagePtr im;
  2786. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) {
  2787. return;
  2788. }
  2789. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2790. gdImageFilledRectangle(im, x1, y1, x2, y2, col);
  2791. RETURN_TRUE;
  2792. }
  2793. /* }}} */
  2794. /* {{{ proto bool imagearc(resource im, int cx, int cy, int w, int h, int s, int e, int col)
  2795. Draw a partial ellipse */
  2796. PHP_FUNCTION(imagearc)
  2797. {
  2798. zval *IM;
  2799. long cx, cy, w, h, ST, E, col;
  2800. gdImagePtr im;
  2801. int e, st;
  2802. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col) == FAILURE) {
  2803. return;
  2804. }
  2805. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2806. e = E;
  2807. if (e < 0) {
  2808. e %= 360;
  2809. }
  2810. st = ST;
  2811. if (st < 0) {
  2812. st %= 360;
  2813. }
  2814. gdImageArc(im, cx, cy, w, h, st, e, col);
  2815. RETURN_TRUE;
  2816. }
  2817. /* }}} */
  2818. /* {{{ proto bool imageellipse(resource im, int cx, int cy, int w, int h, int color)
  2819. Draw an ellipse */
  2820. PHP_FUNCTION(imageellipse)
  2821. {
  2822. zval *IM;
  2823. long cx, cy, w, h, color;
  2824. gdImagePtr im;
  2825. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
  2826. return;
  2827. }
  2828. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2829. gdImageEllipse(im, cx, cy, w, h, color);
  2830. RETURN_TRUE;
  2831. }
  2832. /* }}} */
  2833. /* {{{ proto bool imagefilltoborder(resource im, int x, int y, int border, int col)
  2834. Flood fill to specific color */
  2835. PHP_FUNCTION(imagefilltoborder)
  2836. {
  2837. zval *IM;
  2838. long x, y, border, col;
  2839. gdImagePtr im;
  2840. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &x, &y, &border, &col) == FAILURE) {
  2841. return;
  2842. }
  2843. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2844. gdImageFillToBorder(im, x, y, border, col);
  2845. RETURN_TRUE;
  2846. }
  2847. /* }}} */
  2848. /* {{{ proto bool imagefill(resource im, int x, int y, int col)
  2849. Flood fill */
  2850. PHP_FUNCTION(imagefill)
  2851. {
  2852. zval *IM;
  2853. long x, y, col;
  2854. gdImagePtr im;
  2855. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &IM, &x, &y, &col) == FAILURE) {
  2856. return;
  2857. }
  2858. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2859. gdImageFill(im, x, y, col);
  2860. RETURN_TRUE;
  2861. }
  2862. /* }}} */
  2863. /* {{{ proto int imagecolorstotal(resource im)
  2864. Find out the number of colors in an image's palette */
  2865. PHP_FUNCTION(imagecolorstotal)
  2866. {
  2867. zval *IM;
  2868. gdImagePtr im;
  2869. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
  2870. return;
  2871. }
  2872. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2873. RETURN_LONG(gdImageColorsTotal(im));
  2874. }
  2875. /* }}} */
  2876. /* {{{ proto int imagecolortransparent(resource im [, int col])
  2877. Define a color as transparent */
  2878. PHP_FUNCTION(imagecolortransparent)
  2879. {
  2880. zval *IM;
  2881. long COL = 0;
  2882. gdImagePtr im;
  2883. int argc = ZEND_NUM_ARGS();
  2884. if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &IM, &COL) == FAILURE) {
  2885. return;
  2886. }
  2887. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2888. if (argc > 1) {
  2889. gdImageColorTransparent(im, COL);
  2890. }
  2891. RETURN_LONG(gdImageGetTransparent(im));
  2892. }
  2893. /* }}} */
  2894. /* {{{ proto int imageinterlace(resource im [, int interlace])
  2895. Enable or disable interlace */
  2896. PHP_FUNCTION(imageinterlace)
  2897. {
  2898. zval *IM;
  2899. int argc = ZEND_NUM_ARGS();
  2900. long INT = 0;
  2901. gdImagePtr im;
  2902. if (zend_parse_parameters(argc TSRMLS_CC, "r|l", &IM, &INT) == FAILURE) {
  2903. return;
  2904. }
  2905. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2906. if (argc > 1) {
  2907. gdImageInterlace(im, INT);
  2908. }
  2909. RETURN_LONG(gdImageGetInterlaced(im));
  2910. }
  2911. /* }}} */
  2912. /* {{{ php_imagepolygon
  2913. arg = 0 normal polygon
  2914. arg = 1 filled polygon */
  2915. /* im, points, num_points, col */
  2916. static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
  2917. {
  2918. zval *IM, *POINTS;
  2919. long NPOINTS, COL;
  2920. zval **var = NULL;
  2921. gdImagePtr im;
  2922. gdPointPtr points;
  2923. int npoints, col, nelem, i;
  2924. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rall", &IM, &POINTS, &NPOINTS, &COL) == FAILURE) {
  2925. return;
  2926. }
  2927. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  2928. npoints = NPOINTS;
  2929. col = COL;
  2930. nelem = zend_hash_num_elements(Z_ARRVAL_P(POINTS));
  2931. if (nelem < 6) {
  2932. php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have at least 3 points in your array");
  2933. RETURN_FALSE;
  2934. }
  2935. if (npoints <= 0) {
  2936. php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must give a positive number of points");
  2937. RETURN_FALSE;
  2938. }
  2939. if (nelem < npoints * 2) {
  2940. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Trying to use %d points in array with only %d points", npoints, nelem/2);
  2941. RETURN_FALSE;
  2942. }
  2943. points = (gdPointPtr) safe_emalloc(npoints, sizeof(gdPoint), 0);
  2944. for (i = 0; i < npoints; i++) {
  2945. if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2), (void **) &var) == SUCCESS) {
  2946. SEPARATE_ZVAL((var));
  2947. convert_to_long(*var);
  2948. points[i].x = Z_LVAL_PP(var);
  2949. }
  2950. if (zend_hash_index_find(Z_ARRVAL_P(POINTS), (i * 2) + 1, (void **) &var) == SUCCESS) {
  2951. SEPARATE_ZVAL(var);
  2952. convert_to_long(*var);
  2953. points[i].y = Z_LVAL_PP(var);
  2954. }
  2955. }
  2956. if (filled) {
  2957. gdImageFilledPolygon(im, points, npoints, col);
  2958. } else {
  2959. gdImagePolygon(im, points, npoints, col);
  2960. }
  2961. efree(points);
  2962. RETURN_TRUE;
  2963. }
  2964. /* }}} */
  2965. /* {{{ proto bool imagepolygon(resource im, array point, int num_points, int col)
  2966. Draw a polygon */
  2967. PHP_FUNCTION(imagepolygon)
  2968. {
  2969. php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  2970. }
  2971. /* }}} */
  2972. /* {{{ proto bool imagefilledpolygon(resource im, array point, int num_points, int col)
  2973. Draw a filled polygon */
  2974. PHP_FUNCTION(imagefilledpolygon)
  2975. {
  2976. php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  2977. }
  2978. /* }}} */
  2979. /* {{{ php_find_gd_font
  2980. */
  2981. static gdFontPtr php_find_gd_font(int size TSRMLS_DC)
  2982. {
  2983. gdFontPtr font;
  2984. int ind_type;
  2985. switch (size) {
  2986. case 1:
  2987. font = gdFontTiny;
  2988. break;
  2989. case 2:
  2990. font = gdFontSmall;
  2991. break;
  2992. case 3:
  2993. font = gdFontMediumBold;
  2994. break;
  2995. case 4:
  2996. font = gdFontLarge;
  2997. break;
  2998. case 5:
  2999. font = gdFontGiant;
  3000. break;
  3001. default:
  3002. font = zend_list_find(size - 5, &ind_type);
  3003. if (!font || ind_type != le_gd_font) {
  3004. if (size < 1) {
  3005. font = gdFontTiny;
  3006. } else {
  3007. font = gdFontGiant;
  3008. }
  3009. }
  3010. break;
  3011. }
  3012. return font;
  3013. }
  3014. /* }}} */
  3015. /* {{{ php_imagefontsize
  3016. * arg = 0 ImageFontWidth
  3017. * arg = 1 ImageFontHeight
  3018. */
  3019. static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
  3020. {
  3021. long SIZE;
  3022. gdFontPtr font;
  3023. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &SIZE) == FAILURE) {
  3024. return;
  3025. }
  3026. font = php_find_gd_font(SIZE TSRMLS_CC);
  3027. RETURN_LONG(arg ? font->h : font->w);
  3028. }
  3029. /* }}} */
  3030. /* {{{ proto int imagefontwidth(int font)
  3031. Get font width */
  3032. PHP_FUNCTION(imagefontwidth)
  3033. {
  3034. php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  3035. }
  3036. /* }}} */
  3037. /* {{{ proto int imagefontheight(int font)
  3038. Get font height */
  3039. PHP_FUNCTION(imagefontheight)
  3040. {
  3041. php_imagefontsize(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  3042. }
  3043. /* }}} */
  3044. /* {{{ php_gdimagecharup
  3045. * workaround for a bug in gd 1.2 */
  3046. static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color)
  3047. {
  3048. int cx, cy, px, py, fline;
  3049. cx = 0;
  3050. cy = 0;
  3051. if ((c < f->offset) || (c >= (f->offset + f->nchars))) {
  3052. return;
  3053. }
  3054. fline = (c - f->offset) * f->h * f->w;
  3055. for (py = y; (py > (y - f->w)); py--) {
  3056. for (px = x; (px < (x + f->h)); px++) {
  3057. if (f->data[fline + cy * f->w + cx]) {
  3058. gdImageSetPixel(im, px, py, color);
  3059. }
  3060. cy++;
  3061. }
  3062. cy = 0;
  3063. cx++;
  3064. }
  3065. }
  3066. /* }}} */
  3067. /* {{{ php_imagechar
  3068. * arg = 0 ImageChar
  3069. * arg = 1 ImageCharUp
  3070. * arg = 2 ImageString
  3071. * arg = 3 ImageStringUp
  3072. */
  3073. static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
  3074. {
  3075. zval *IM;
  3076. long SIZE, X, Y, COL;
  3077. char *C;
  3078. int C_len;
  3079. gdImagePtr im;
  3080. int ch = 0, col, x, y, size, i, l = 0;
  3081. unsigned char *str = NULL;
  3082. gdFontPtr font;
  3083. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllsl", &IM, &SIZE, &X, &Y, &C, &C_len, &COL) == FAILURE) {
  3084. return;
  3085. }
  3086. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  3087. col = COL;
  3088. if (mode < 2) {
  3089. ch = (int)((unsigned char)*C);
  3090. } else {
  3091. str = (unsigned char *) estrndup(C, C_len);
  3092. l = strlen((char *)str);
  3093. }
  3094. y = Y;
  3095. x = X;
  3096. size = SIZE;
  3097. font = php_find_gd_font(size TSRMLS_CC);
  3098. switch (mode) {
  3099. case 0:
  3100. gdImageChar(im, font, x, y, ch, col);
  3101. break;
  3102. case 1:
  3103. php_gdimagecharup(im, font, x, y, ch, col);
  3104. break;
  3105. case 2:
  3106. for (i = 0; (i < l); i++) {
  3107. gdImageChar(im, font, x, y, (int) ((unsigned char) str[i]), col);
  3108. x += font->w;
  3109. }
  3110. break;
  3111. case 3: {
  3112. for (i = 0; (i < l); i++) {
  3113. /* php_gdimagecharup(im, font, x, y, (int) str[i], col); */
  3114. gdImageCharUp(im, font, x, y, (int) str[i], col);
  3115. y -= font->w;
  3116. }
  3117. break;
  3118. }
  3119. }
  3120. if (str) {
  3121. efree(str);
  3122. }
  3123. RETURN_TRUE;
  3124. }
  3125. /* }}} */
  3126. /* {{{ proto bool imagechar(resource im, int font, int x, int y, string c, int col)
  3127. Draw a character */
  3128. PHP_FUNCTION(imagechar)
  3129. {
  3130. php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
  3131. }
  3132. /* }}} */
  3133. /* {{{ proto bool imagecharup(resource im, int font, int x, int y, string c, int col)
  3134. Draw a character rotated 90 degrees counter-clockwise */
  3135. PHP_FUNCTION(imagecharup)
  3136. {
  3137. php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
  3138. }
  3139. /* }}} */
  3140. /* {{{ proto bool imagestring(resource im, int font, int x, int y, string str, int col)
  3141. Draw a string horizontally */
  3142. PHP_FUNCTION(imagestring)
  3143. {
  3144. php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
  3145. }
  3146. /* }}} */
  3147. /* {{{ proto bool imagestringup(resource im, int font, int x, int y, string str, int col)
  3148. Draw a string vertically - rotated 90 degrees counter-clockwise */
  3149. PHP_FUNCTION(imagestringup)
  3150. {
  3151. php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
  3152. }
  3153. /* }}} */
  3154. /* {{{ proto bool imagecopy(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h)
  3155. Copy part of an image */
  3156. PHP_FUNCTION(imagecopy)
  3157. {
  3158. zval *SIM, *DIM;
  3159. long SX, SY, SW, SH, DX, DY;
  3160. gdImagePtr im_dst, im_src;
  3161. int srcH, srcW, srcY, srcX, dstY, dstX;
  3162. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) {
  3163. return;
  3164. }
  3165. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  3166. ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
  3167. srcX = SX;
  3168. srcY = SY;
  3169. srcH = SH;
  3170. srcW = SW;
  3171. dstX = DX;
  3172. dstY = DY;
  3173. gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH);
  3174. RETURN_TRUE;
  3175. }
  3176. /* }}} */
  3177. #if HAVE_LIBGD15
  3178. /* {{{ proto bool imagecopymerge(resource src_im, resource dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct)
  3179. Merge one part of an image with another */
  3180. PHP_FUNCTION(imagecopymerge)
  3181. {
  3182. zval *SIM, *DIM;
  3183. long SX, SY, SW, SH, DX, DY, PCT;
  3184. gdImagePtr im_dst, im_src;
  3185. int srcH, srcW, srcY, srcX, dstY, dstX, pct;
  3186. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) {
  3187. return;
  3188. }
  3189. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  3190. ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
  3191. srcX = SX;
  3192. srcY = SY;
  3193. srcH = SH;
  3194. srcW = SW;
  3195. dstX = DX;
  3196. dstY = DY;
  3197. pct = PCT;
  3198. gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
  3199. RETURN_TRUE;
  3200. }
  3201. /* }}} */
  3202. /* {{{ proto bool imagecopymergegray(resource src_im, resource dst_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h, int pct)
  3203. Merge one part of an image with another */
  3204. PHP_FUNCTION(imagecopymergegray)
  3205. {
  3206. zval *SIM, *DIM;
  3207. long SX, SY, SW, SH, DX, DY, PCT;
  3208. gdImagePtr im_dst, im_src;
  3209. int srcH, srcW, srcY, srcX, dstY, dstX, pct;
  3210. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) {
  3211. return;
  3212. }
  3213. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  3214. ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
  3215. srcX = SX;
  3216. srcY = SY;
  3217. srcH = SH;
  3218. srcW = SW;
  3219. dstX = DX;
  3220. dstY = DY;
  3221. pct = PCT;
  3222. gdImageCopyMergeGray(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
  3223. RETURN_TRUE;
  3224. }
  3225. /* }}} */
  3226. #endif
  3227. /* {{{ proto bool imagecopyresized(resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h)
  3228. Copy and resize part of an image */
  3229. PHP_FUNCTION(imagecopyresized)
  3230. {
  3231. zval *SIM, *DIM;
  3232. long SX, SY, SW, SH, DX, DY, DW, DH;
  3233. gdImagePtr im_dst, im_src;
  3234. int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX;
  3235. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) {
  3236. return;
  3237. }
  3238. ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
  3239. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  3240. srcX = SX;
  3241. srcY = SY;
  3242. srcH = SH;
  3243. srcW = SW;
  3244. dstX = DX;
  3245. dstY = DY;
  3246. dstH = DH;
  3247. dstW = DW;
  3248. if (dstW <= 0 || dstH <= 0 || srcW <= 0 || srcH <= 0) {
  3249. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid image dimensions");
  3250. RETURN_FALSE;
  3251. }
  3252. gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
  3253. RETURN_TRUE;
  3254. }
  3255. /* }}} */
  3256. /* {{{ proto int imagesx(resource im)
  3257. Get image width */
  3258. PHP_FUNCTION(imagesx)
  3259. {
  3260. zval *IM;
  3261. gdImagePtr im;
  3262. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
  3263. return;
  3264. }
  3265. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  3266. RETURN_LONG(gdImageSX(im));
  3267. }
  3268. /* }}} */
  3269. /* {{{ proto int imagesy(resource im)
  3270. Get image height */
  3271. PHP_FUNCTION(imagesy)
  3272. {
  3273. zval *IM;
  3274. gdImagePtr im;
  3275. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &IM) == FAILURE) {
  3276. return;
  3277. }
  3278. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  3279. RETURN_LONG(gdImageSY(im));
  3280. }
  3281. /* }}} */
  3282. #ifdef ENABLE_GD_TTF
  3283. #define TTFTEXT_DRAW 0
  3284. #define TTFTEXT_BBOX 1
  3285. #endif
  3286. #ifdef ENABLE_GD_TTF
  3287. #if HAVE_LIBFREETYPE && HAVE_GD_STRINGFTEX
  3288. /* {{{ proto array imageftbbox(float size, float angle, string font_file, string text [, array extrainfo])
  3289. Give the bounding box of a text using fonts via freetype2 */
  3290. PHP_FUNCTION(imageftbbox)
  3291. {
  3292. php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 1);
  3293. }
  3294. /* }}} */
  3295. /* {{{ proto array imagefttext(resource im, float size, float angle, int x, int y, int col, string font_file, string text [, array extrainfo])
  3296. Write text to the image using fonts via freetype2 */
  3297. PHP_FUNCTION(imagefttext)
  3298. {
  3299. php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
  3300. }
  3301. /* }}} */
  3302. #endif
  3303. /* {{{ proto array imagettfbbox(float size, float angle, string font_file, string text)
  3304. Give the bounding box of a text using TrueType fonts */
  3305. PHP_FUNCTION(imagettfbbox)
  3306. {
  3307. php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_BBOX, 0);
  3308. }
  3309. /* }}} */
  3310. /* {{{ proto array imagettftext(resource im, float size, float angle, int x, int y, int col, string font_file, string text)
  3311. Write text to the image using a TrueType font */
  3312. PHP_FUNCTION(imagettftext)
  3313. {
  3314. php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 0);
  3315. }
  3316. /* }}} */
  3317. /* {{{ php_imagettftext_common
  3318. */
  3319. static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int extended)
  3320. {
  3321. zval *IM, *EXT = NULL;
  3322. gdImagePtr im=NULL;
  3323. long col = -1, x = -1, y = -1;
  3324. int str_len, fontname_len, i, brect[8];
  3325. double ptsize, angle;
  3326. char *str = NULL, *fontname = NULL;
  3327. char *error = NULL;
  3328. int argc = ZEND_NUM_ARGS();
  3329. #if HAVE_GD_STRINGFTEX
  3330. gdFTStringExtra strex = {0};
  3331. #endif
  3332. #if !HAVE_GD_STRINGFTEX
  3333. assert(!extended);
  3334. #endif
  3335. if (mode == TTFTEXT_BBOX) {
  3336. if (argc < 4 || argc > ((extended) ? 5 : 4)) {
  3337. ZEND_WRONG_PARAM_COUNT();
  3338. } else if (zend_parse_parameters(argc TSRMLS_CC, "ddss|a", &ptsize, &angle, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
  3339. RETURN_FALSE;
  3340. }
  3341. } else {
  3342. if (argc < 8 || argc > ((extended) ? 9 : 8)) {
  3343. ZEND_WRONG_PARAM_COUNT();
  3344. } else if (zend_parse_parameters(argc TSRMLS_CC, "rddlllss|a", &IM, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) {
  3345. RETURN_FALSE;
  3346. }
  3347. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  3348. }
  3349. /* convert angle to radians */
  3350. angle = angle * (M_PI/180);
  3351. #if HAVE_GD_STRINGFTEX
  3352. if (extended && EXT) { /* parse extended info */
  3353. HashPosition pos;
  3354. /* walk the assoc array */
  3355. zend_hash_internal_pointer_reset_ex(HASH_OF(EXT), &pos);
  3356. do {
  3357. zval ** item;
  3358. char * key;
  3359. ulong num_key;
  3360. if (zend_hash_get_current_key_ex(HASH_OF(EXT), &key, NULL, &num_key, 0, &pos) != HASH_KEY_IS_STRING) {
  3361. continue;
  3362. }
  3363. if (zend_hash_get_current_data_ex(HASH_OF(EXT), (void **) &item, &pos) == FAILURE) {
  3364. continue;
  3365. }
  3366. if (strcmp("linespacing", key) == 0) {
  3367. convert_to_double_ex(item);
  3368. strex.flags |= gdFTEX_LINESPACE;
  3369. strex.linespacing = Z_DVAL_PP(item);
  3370. }
  3371. } while (zend_hash_move_forward_ex(HASH_OF(EXT), &pos) == SUCCESS);
  3372. }
  3373. #endif
  3374. #ifdef VIRTUAL_DIR
  3375. {
  3376. char tmp_font_path[MAXPATHLEN];
  3377. if (!VCWD_REALPATH(fontname, tmp_font_path)) {
  3378. fontname = NULL;
  3379. }
  3380. }
  3381. #endif
  3382. PHP_GD_CHECK_OPEN_BASEDIR(fontname, "Invalid font filename");
  3383. #ifdef USE_GD_IMGSTRTTF
  3384. # if HAVE_GD_STRINGFTEX
  3385. if (extended) {
  3386. error = gdImageStringFTEx(im, brect, col, fontname, ptsize, angle, x, y, str, &strex);
  3387. }
  3388. else
  3389. # endif
  3390. # if HAVE_GD_STRINGFT
  3391. error = gdImageStringFT(im, brect, col, fontname, ptsize, angle, x, y, str);
  3392. # elif HAVE_GD_STRINGTTF
  3393. error = gdImageStringTTF(im, brect, col, fontname, ptsize, angle, x, y, str);
  3394. # endif
  3395. #endif
  3396. if (error) {
  3397. php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error);
  3398. RETURN_FALSE;
  3399. }
  3400. array_init(return_value);
  3401. /* return array with the text's bounding box */
  3402. for (i = 0; i < 8; i++) {
  3403. add_next_index_long(return_value, brect[i]);
  3404. }
  3405. }
  3406. /* }}} */
  3407. #endif /* ENABLE_GD_TTF */
  3408. #if HAVE_LIBT1
  3409. /* {{{ php_free_ps_font
  3410. */
  3411. static void php_free_ps_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  3412. {
  3413. int *font = (int *) rsrc->ptr;
  3414. T1_DeleteFont(*font);
  3415. efree(font);
  3416. }
  3417. /* }}} */
  3418. /* {{{ php_free_ps_enc
  3419. */
  3420. static void php_free_ps_enc(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  3421. {
  3422. char **enc = (char **) rsrc->ptr;
  3423. T1_DeleteEncoding(enc);
  3424. }
  3425. /* }}} */
  3426. /* {{{ proto resource imagepsloadfont(string pathname)
  3427. Load a new font from specified file */
  3428. PHP_FUNCTION(imagepsloadfont)
  3429. {
  3430. char *file;
  3431. int file_len, f_ind, *font;
  3432. #ifdef PHP_WIN32
  3433. struct stat st;
  3434. #endif
  3435. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &file_len) == FAILURE) {
  3436. return;
  3437. }
  3438. #ifdef PHP_WIN32
  3439. if (VCWD_STAT(file, &st) < 0) {
  3440. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Font file not found (%s)", file);
  3441. RETURN_FALSE;
  3442. }
  3443. #endif
  3444. f_ind = T1_AddFont(file);
  3445. if (f_ind < 0) {
  3446. php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error (%i): %s", f_ind, T1_StrError(f_ind));
  3447. RETURN_FALSE;
  3448. }
  3449. if (T1_LoadFont(f_ind)) {
  3450. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load the font");
  3451. RETURN_FALSE;
  3452. }
  3453. font = (int *) emalloc(sizeof(int));
  3454. *font = f_ind;
  3455. ZEND_REGISTER_RESOURCE(return_value, font, le_ps_font);
  3456. }
  3457. /* }}} */
  3458. /* {{{ proto int imagepscopyfont(int font_index)
  3459. Make a copy of a font for purposes like extending or reenconding */
  3460. /* The function in t1lib which this function uses seem to be buggy...
  3461. PHP_FUNCTION(imagepscopyfont)
  3462. {
  3463. int l_ind, type;
  3464. gd_ps_font *nf_ind, *of_ind;
  3465. long fnt;
  3466. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fnt) == FAILURE) {
  3467. return;
  3468. }
  3469. of_ind = zend_list_find(fnt, &type);
  3470. if (type != le_ps_font) {
  3471. php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld is not a Type 1 font index", fnt);
  3472. RETURN_FALSE;
  3473. }
  3474. nf_ind = emalloc(sizeof(gd_ps_font));
  3475. nf_ind->font_id = T1_CopyFont(of_ind->font_id);
  3476. if (nf_ind->font_id < 0) {
  3477. l_ind = nf_ind->font_id;
  3478. efree(nf_ind);
  3479. switch (l_ind) {
  3480. case -1:
  3481. php_error_docref(NULL TSRMLS_CC, E_WARNING, "FontID %d is not loaded in memory", l_ind);
  3482. RETURN_FALSE;
  3483. break;
  3484. case -2:
  3485. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tried to copy a logical font");
  3486. RETURN_FALSE;
  3487. break;
  3488. case -3:
  3489. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Memory allocation fault in t1lib");
  3490. RETURN_FALSE;
  3491. break;
  3492. default:
  3493. php_error_docref(NULL TSRMLS_CC, E_WARNING, "An unknown error occurred in t1lib");
  3494. RETURN_FALSE;
  3495. break;
  3496. }
  3497. }
  3498. nf_ind->extend = 1;
  3499. l_ind = zend_list_insert(nf_ind, le_ps_font);
  3500. RETURN_LONG(l_ind);
  3501. }
  3502. */
  3503. /* }}} */
  3504. /* {{{ proto bool imagepsfreefont(resource font_index)
  3505. Free memory used by a font */
  3506. PHP_FUNCTION(imagepsfreefont)
  3507. {
  3508. zval *fnt;
  3509. int *f_ind;
  3510. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &fnt) == FAILURE) {
  3511. return;
  3512. }
  3513. ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
  3514. zend_list_delete(Z_LVAL_P(fnt));
  3515. RETURN_TRUE;
  3516. }
  3517. /* }}} */
  3518. /* {{{ proto bool imagepsencodefont(resource font_index, string filename)
  3519. To change a fonts character encoding vector */
  3520. PHP_FUNCTION(imagepsencodefont)
  3521. {
  3522. zval *fnt;
  3523. char *enc, **enc_vector;
  3524. int enc_len, *f_ind;
  3525. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &fnt, &enc, &enc_len) == FAILURE) {
  3526. return;
  3527. }
  3528. ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
  3529. if ((enc_vector = T1_LoadEncoding(enc)) == NULL) {
  3530. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't load encoding vector from %s", enc);
  3531. RETURN_FALSE;
  3532. }
  3533. T1_DeleteAllSizes(*f_ind);
  3534. if (T1_ReencodeFont(*f_ind, enc_vector)) {
  3535. T1_DeleteEncoding(enc_vector);
  3536. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't re-encode font");
  3537. RETURN_FALSE;
  3538. }
  3539. zend_list_insert(enc_vector, le_ps_enc);
  3540. RETURN_TRUE;
  3541. }
  3542. /* }}} */
  3543. /* {{{ proto bool imagepsextendfont(resource font_index, float extend)
  3544. Extend or or condense (if extend < 1) a font */
  3545. PHP_FUNCTION(imagepsextendfont)
  3546. {
  3547. zval *fnt;
  3548. double ext;
  3549. int *f_ind;
  3550. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &fnt, &ext) == FAILURE) {
  3551. return;
  3552. }
  3553. ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
  3554. T1_DeleteAllSizes(*f_ind);
  3555. if (ext <= 0) {
  3556. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second parameter %F out of range (must be > 0)", ext);
  3557. RETURN_FALSE;
  3558. }
  3559. if (T1_ExtendFont(*f_ind, ext) != 0) {
  3560. RETURN_FALSE;
  3561. }
  3562. RETURN_TRUE;
  3563. }
  3564. /* }}} */
  3565. /* {{{ proto bool imagepsslantfont(resource font_index, float slant)
  3566. Slant a font */
  3567. PHP_FUNCTION(imagepsslantfont)
  3568. {
  3569. zval *fnt;
  3570. double slt;
  3571. int *f_ind;
  3572. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &fnt, &slt) == FAILURE) {
  3573. return;
  3574. }
  3575. ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
  3576. if (T1_SlantFont(*f_ind, slt) != 0) {
  3577. RETURN_FALSE;
  3578. }
  3579. RETURN_TRUE;
  3580. }
  3581. /* }}} */
  3582. /* {{{ proto array imagepstext(resource image, string text, resource font, int size, int foreground, int background, int xcoord, int ycoord [, int space [, int tightness [, float angle [, int antialias])
  3583. Rasterize a string over an image */
  3584. PHP_FUNCTION(imagepstext)
  3585. {
  3586. zval *img, *fnt;
  3587. int i, j;
  3588. long _fg, _bg, x, y, size, space = 0, aa_steps = 4, width = 0;
  3589. int *f_ind;
  3590. int h_lines, v_lines, c_ind;
  3591. int rd, gr, bl, fg_rd, fg_gr, fg_bl, bg_rd, bg_gr, bg_bl;
  3592. int fg_al, bg_al, al;
  3593. int aa[16];
  3594. int amount_kern, add_width;
  3595. double angle = 0.0, extend;
  3596. unsigned long aa_greys[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
  3597. gdImagePtr bg_img;
  3598. GLYPH *str_img;
  3599. T1_OUTLINE *char_path, *str_path;
  3600. T1_TMATRIX *transform = NULL;
  3601. char *str;
  3602. int str_len;
  3603. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrlllll|lldl", &img, &str, &str_len, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
  3604. return;
  3605. }
  3606. if (aa_steps != 4 && aa_steps != 16) {
  3607. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Antialias steps must be 4 or 16");
  3608. RETURN_FALSE;
  3609. }
  3610. ZEND_FETCH_RESOURCE(bg_img, gdImagePtr, &img, -1, "Image", le_gd);
  3611. ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
  3612. /* Ensure that the provided colors are valid */
  3613. if (_fg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
  3614. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Foreground color index %ld out of range", _fg);
  3615. RETURN_FALSE;
  3616. }
  3617. if (_bg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
  3618. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Background color index %ld out of range", _bg);
  3619. RETURN_FALSE;
  3620. }
  3621. fg_rd = gdImageRed (bg_img, _fg);
  3622. fg_gr = gdImageGreen(bg_img, _fg);
  3623. fg_bl = gdImageBlue (bg_img, _fg);
  3624. fg_al = gdImageAlpha(bg_img, _fg);
  3625. bg_rd = gdImageRed (bg_img, _bg);
  3626. bg_gr = gdImageGreen(bg_img, _bg);
  3627. bg_bl = gdImageBlue (bg_img, _bg);
  3628. bg_al = gdImageAlpha(bg_img, _bg);
  3629. for (i = 0; i < aa_steps; i++) {
  3630. rd = bg_rd + (double) (fg_rd - bg_rd) / aa_steps * (i + 1);
  3631. gr = bg_gr + (double) (fg_gr - bg_gr) / aa_steps * (i + 1);
  3632. bl = bg_bl + (double) (fg_bl - bg_bl) / aa_steps * (i + 1);
  3633. al = bg_al + (double) (fg_al - bg_al) / aa_steps * (i + 1);
  3634. aa[i] = gdImageColorResolveAlpha(bg_img, rd, gr, bl, al);
  3635. }
  3636. T1_AASetBitsPerPixel(8);
  3637. switch (aa_steps) {
  3638. case 4:
  3639. T1_AASetGrayValues(0, 1, 2, 3, 4);
  3640. T1_AASetLevel(T1_AA_LOW);
  3641. break;
  3642. case 16:
  3643. T1_AAHSetGrayValues(aa_greys);
  3644. T1_AASetLevel(T1_AA_HIGH);
  3645. break;
  3646. default:
  3647. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid value %ld as number of steps for antialiasing", aa_steps);
  3648. RETURN_FALSE;
  3649. }
  3650. if (angle) {
  3651. transform = T1_RotateMatrix(NULL, angle);
  3652. }
  3653. if (width) {
  3654. extend = T1_GetExtend(*f_ind);
  3655. str_path = T1_GetCharOutline(*f_ind, str[0], size, transform);
  3656. if (!str_path) {
  3657. if (T1_errno) {
  3658. php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
  3659. }
  3660. RETURN_FALSE;
  3661. }
  3662. for (i = 1; i < str_len; i++) {
  3663. amount_kern = (int) T1_GetKerning(*f_ind, str[i - 1], str[i]);
  3664. amount_kern += str[i - 1] == ' ' ? space : 0;
  3665. add_width = (int) (amount_kern + width) / extend;
  3666. char_path = T1_GetMoveOutline(*f_ind, add_width, 0, 0, size, transform);
  3667. str_path = T1_ConcatOutlines(str_path, char_path);
  3668. char_path = T1_GetCharOutline(*f_ind, str[i], size, transform);
  3669. str_path = T1_ConcatOutlines(str_path, char_path);
  3670. }
  3671. str_img = T1_AAFillOutline(str_path, 0);
  3672. } else {
  3673. str_img = T1_AASetString(*f_ind, str, str_len, space, T1_KERNING, size, transform);
  3674. }
  3675. if (T1_errno) {
  3676. php_error_docref(NULL TSRMLS_CC, E_WARNING, "T1Lib Error: %s", T1_StrError(T1_errno));
  3677. RETURN_FALSE;
  3678. }
  3679. h_lines = str_img->metrics.ascent - str_img->metrics.descent;
  3680. v_lines = str_img->metrics.rightSideBearing - str_img->metrics.leftSideBearing;
  3681. for (i = 0; i < v_lines; i++) {
  3682. for (j = 0; j < h_lines; j++) {
  3683. switch (str_img->bits[j * v_lines + i]) {
  3684. case 0:
  3685. break;
  3686. default:
  3687. c_ind = aa[str_img->bits[j * v_lines + i] - 1];
  3688. gdImageSetPixel(bg_img, x + str_img->metrics.leftSideBearing + i, y - str_img->metrics.ascent + j, c_ind);
  3689. break;
  3690. }
  3691. }
  3692. }
  3693. array_init(return_value);
  3694. add_next_index_long(return_value, str_img->metrics.leftSideBearing);
  3695. add_next_index_long(return_value, str_img->metrics.descent);
  3696. add_next_index_long(return_value, str_img->metrics.rightSideBearing);
  3697. add_next_index_long(return_value, str_img->metrics.ascent);
  3698. }
  3699. /* }}} */
  3700. /* {{{ proto array imagepsbbox(string text, resource font, int size [, int space, int tightness, float angle])
  3701. Return the bounding box needed by a string if rasterized */
  3702. PHP_FUNCTION(imagepsbbox)
  3703. {
  3704. zval *fnt;
  3705. long sz = 0, sp = 0, wd = 0;
  3706. char *str;
  3707. int i, space = 0, add_width = 0, char_width, amount_kern;
  3708. int cur_x, cur_y, dx, dy;
  3709. int x1, y1, x2, y2, x3, y3, x4, y4;
  3710. int *f_ind;
  3711. int str_len, per_char = 0;
  3712. int argc = ZEND_NUM_ARGS();
  3713. double angle = 0, sin_a = 0, cos_a = 0;
  3714. BBox char_bbox, str_bbox = {0, 0, 0, 0};
  3715. if (argc != 3 && argc != 6) {
  3716. ZEND_WRONG_PARAM_COUNT();
  3717. }
  3718. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "srl|lld", &str, &str_len, &fnt, &sz, &sp, &wd, &angle) == FAILURE) {
  3719. return;
  3720. }
  3721. if (argc == 6) {
  3722. space = sp;
  3723. add_width = wd;
  3724. angle = angle * M_PI / 180;
  3725. sin_a = sin(angle);
  3726. cos_a = cos(angle);
  3727. per_char = add_width || angle ? 1 : 0;
  3728. }
  3729. ZEND_FETCH_RESOURCE(f_ind, int *, &fnt, -1, "Type 1 font", le_ps_font);
  3730. #define max(a, b) (a > b ? a : b)
  3731. #define min(a, b) (a < b ? a : b)
  3732. #define new_x(a, b) (int) ((a) * cos_a - (b) * sin_a)
  3733. #define new_y(a, b) (int) ((a) * sin_a + (b) * cos_a)
  3734. if (per_char) {
  3735. space += T1_GetCharWidth(*f_ind, ' ');
  3736. cur_x = cur_y = 0;
  3737. for (i = 0; i < str_len; i++) {
  3738. if (str[i] == ' ') {
  3739. char_bbox.llx = char_bbox.lly = char_bbox.ury = 0;
  3740. char_bbox.urx = char_width = space;
  3741. } else {
  3742. char_bbox = T1_GetCharBBox(*f_ind, str[i]);
  3743. char_width = T1_GetCharWidth(*f_ind, str[i]);
  3744. }
  3745. amount_kern = i ? T1_GetKerning(*f_ind, str[i - 1], str[i]) : 0;
  3746. /* Transfer character bounding box to right place */
  3747. x1 = new_x(char_bbox.llx, char_bbox.lly) + cur_x;
  3748. y1 = new_y(char_bbox.llx, char_bbox.lly) + cur_y;
  3749. x2 = new_x(char_bbox.llx, char_bbox.ury) + cur_x;
  3750. y2 = new_y(char_bbox.llx, char_bbox.ury) + cur_y;
  3751. x3 = new_x(char_bbox.urx, char_bbox.ury) + cur_x;
  3752. y3 = new_y(char_bbox.urx, char_bbox.ury) + cur_y;
  3753. x4 = new_x(char_bbox.urx, char_bbox.lly) + cur_x;
  3754. y4 = new_y(char_bbox.urx, char_bbox.lly) + cur_y;
  3755. /* Find min & max values and compare them with current bounding box */
  3756. str_bbox.llx = min(str_bbox.llx, min(x1, min(x2, min(x3, x4))));
  3757. str_bbox.lly = min(str_bbox.lly, min(y1, min(y2, min(y3, y4))));
  3758. str_bbox.urx = max(str_bbox.urx, max(x1, max(x2, max(x3, x4))));
  3759. str_bbox.ury = max(str_bbox.ury, max(y1, max(y2, max(y3, y4))));
  3760. /* Move to the next base point */
  3761. dx = new_x(char_width + add_width + amount_kern, 0);
  3762. dy = new_y(char_width + add_width + amount_kern, 0);
  3763. cur_x += dx;
  3764. cur_y += dy;
  3765. /*
  3766. printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", x1, y1, x2, y2, x3, y3, x4, y4, char_bbox.llx, char_bbox.lly, char_bbox.urx, char_bbox.ury, char_width, amount_kern, cur_x, cur_y, dx, dy);
  3767. */
  3768. }
  3769. } else {
  3770. str_bbox = T1_GetStringBBox(*f_ind, str, str_len, space, T1_KERNING);
  3771. }
  3772. if (T1_errno) {
  3773. RETURN_FALSE;
  3774. }
  3775. array_init(return_value);
  3776. /*
  3777. printf("%d %d %d %d\n", str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury);
  3778. */
  3779. add_next_index_long(return_value, (int) ceil(((double) str_bbox.llx)*sz/1000));
  3780. add_next_index_long(return_value, (int) ceil(((double) str_bbox.lly)*sz/1000));
  3781. add_next_index_long(return_value, (int) ceil(((double) str_bbox.urx)*sz/1000));
  3782. add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*sz/1000));
  3783. }
  3784. /* }}} */
  3785. #endif
  3786. #ifdef HAVE_GD_WBMP
  3787. /* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
  3788. Output WBMP image to browser or file */
  3789. PHP_FUNCTION(image2wbmp)
  3790. {
  3791. _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_CONVERT_WBM, "WBMP", _php_image_bw_convert);
  3792. }
  3793. /* }}} */
  3794. #endif /* HAVE_GD_WBMP */
  3795. #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
  3796. /* {{{ proto bool jpeg2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
  3797. Convert JPEG image to WBMP image */
  3798. PHP_FUNCTION(jpeg2wbmp)
  3799. {
  3800. _php_image_convert(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG);
  3801. }
  3802. /* }}} */
  3803. #endif
  3804. #if defined(HAVE_GD_PNG) && defined(HAVE_GD_WBMP)
  3805. /* {{{ proto bool png2wbmp (string f_org, string f_dest, int d_height, int d_width, int threshold)
  3806. Convert PNG image to WBMP image */
  3807. PHP_FUNCTION(png2wbmp)
  3808. {
  3809. _php_image_convert(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG);
  3810. }
  3811. /* }}} */
  3812. #endif
  3813. #ifdef HAVE_GD_WBMP
  3814. /* {{{ _php_image_bw_convert
  3815. * It converts a gd Image to bw using a threshold value */
  3816. static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold)
  3817. {
  3818. gdImagePtr im_dest;
  3819. int white, black;
  3820. int color, color_org, median;
  3821. int dest_height = gdImageSY(im_org);
  3822. int dest_width = gdImageSX(im_org);
  3823. int x, y;
  3824. TSRMLS_FETCH();
  3825. im_dest = gdImageCreate(dest_width, dest_height);
  3826. if (im_dest == NULL) {
  3827. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate temporary buffer");
  3828. return;
  3829. }
  3830. white = gdImageColorAllocate(im_dest, 255, 255, 255);
  3831. if (white == -1) {
  3832. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
  3833. return;
  3834. }
  3835. black = gdImageColorAllocate(im_dest, 0, 0, 0);
  3836. if (black == -1) {
  3837. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
  3838. return;
  3839. }
  3840. if (im_org->trueColor) {
  3841. gdImageTrueColorToPalette(im_org, 1, 256);
  3842. }
  3843. for (y = 0; y < dest_height; y++) {
  3844. for (x = 0; x < dest_width; x++) {
  3845. color_org = gdImageGetPixel(im_org, x, y);
  3846. median = (im_org->red[color_org] + im_org->green[color_org] + im_org->blue[color_org]) / 3;
  3847. if (median < threshold) {
  3848. color = black;
  3849. } else {
  3850. color = white;
  3851. }
  3852. gdImageSetPixel (im_dest, x, y, color);
  3853. }
  3854. }
  3855. #ifdef USE_GD_IOCTX
  3856. gdImageWBMPCtx (im_dest, black, out);
  3857. #else
  3858. gdImageWBMP (im_dest, black, out);
  3859. #endif
  3860. }
  3861. /* }}} */
  3862. /* {{{ _php_image_convert
  3863. * _php_image_convert converts jpeg/png images to wbmp and resizes them as needed */
  3864. static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
  3865. {
  3866. char *f_org, *f_dest;
  3867. int f_org_len, f_dest_len;
  3868. long height, width, threshold;
  3869. gdImagePtr im_org, im_dest, im_tmp;
  3870. char *fn_org = NULL;
  3871. char *fn_dest = NULL;
  3872. FILE *org, *dest;
  3873. int dest_height = -1;
  3874. int dest_width = -1;
  3875. int org_height, org_width;
  3876. int white, black;
  3877. int color, color_org, median;
  3878. int int_threshold;
  3879. int x, y;
  3880. float x_ratio, y_ratio;
  3881. #ifdef HAVE_GD_JPG
  3882. long ignore_warning;
  3883. #endif
  3884. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sslll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) {
  3885. return;
  3886. }
  3887. fn_org = f_org;
  3888. fn_dest = f_dest;
  3889. dest_height = height;
  3890. dest_width = width;
  3891. int_threshold = threshold;
  3892. if (strlen(f_org) != f_org_len) {
  3893. RETURN_FALSE;
  3894. }
  3895. if (strlen(f_dest) != f_dest_len) {
  3896. RETURN_FALSE;
  3897. }
  3898. /* Check threshold value */
  3899. if (int_threshold < 0 || int_threshold > 8) {
  3900. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'", int_threshold);
  3901. RETURN_FALSE;
  3902. }
  3903. /* Check origin file */
  3904. PHP_GD_CHECK_OPEN_BASEDIR(fn_org, "Invalid origin filename");
  3905. /* Check destination file */
  3906. PHP_GD_CHECK_OPEN_BASEDIR(fn_dest, "Invalid destination filename");
  3907. /* Open origin file */
  3908. org = VCWD_FOPEN(fn_org, "rb");
  3909. if (!org) {
  3910. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for reading", fn_org);
  3911. RETURN_FALSE;
  3912. }
  3913. /* Open destination file */
  3914. dest = VCWD_FOPEN(fn_dest, "wb");
  3915. if (!dest) {
  3916. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn_dest);
  3917. RETURN_FALSE;
  3918. }
  3919. switch (image_type) {
  3920. #ifdef HAVE_GD_GIF_READ
  3921. case PHP_GDIMG_TYPE_GIF:
  3922. im_org = gdImageCreateFromGif(org);
  3923. if (im_org == NULL) {
  3924. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid GIF file", fn_dest);
  3925. RETURN_FALSE;
  3926. }
  3927. break;
  3928. #endif /* HAVE_GD_GIF_READ */
  3929. #ifdef HAVE_GD_JPG
  3930. case PHP_GDIMG_TYPE_JPG:
  3931. ignore_warning = INI_INT("gd.jpeg_ignore_warning");
  3932. #ifdef HAVE_GD_BUNDLED
  3933. im_org = gdImageCreateFromJpeg(org, ignore_warning);
  3934. #else
  3935. im_org = gdImageCreateFromJpeg(org);
  3936. #endif
  3937. if (im_org == NULL) {
  3938. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid JPEG file", fn_dest);
  3939. RETURN_FALSE;
  3940. }
  3941. break;
  3942. #endif /* HAVE_GD_JPG */
  3943. #ifdef HAVE_GD_PNG
  3944. case PHP_GDIMG_TYPE_PNG:
  3945. im_org = gdImageCreateFromPng(org);
  3946. if (im_org == NULL) {
  3947. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' Not a valid PNG file", fn_dest);
  3948. RETURN_FALSE;
  3949. }
  3950. break;
  3951. #endif /* HAVE_GD_PNG */
  3952. default:
  3953. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Format not supported");
  3954. RETURN_FALSE;
  3955. break;
  3956. }
  3957. org_width = gdImageSX (im_org);
  3958. org_height = gdImageSY (im_org);
  3959. x_ratio = (float) org_width / (float) dest_width;
  3960. y_ratio = (float) org_height / (float) dest_height;
  3961. if (x_ratio > 1 && y_ratio > 1) {
  3962. if (y_ratio > x_ratio) {
  3963. x_ratio = y_ratio;
  3964. } else {
  3965. y_ratio = x_ratio;
  3966. }
  3967. dest_width = (int) (org_width / x_ratio);
  3968. dest_height = (int) (org_height / y_ratio);
  3969. } else {
  3970. x_ratio = (float) dest_width / (float) org_width;
  3971. y_ratio = (float) dest_height / (float) org_height;
  3972. if (y_ratio < x_ratio) {
  3973. x_ratio = y_ratio;
  3974. } else {
  3975. y_ratio = x_ratio;
  3976. }
  3977. dest_width = (int) (org_width * x_ratio);
  3978. dest_height = (int) (org_height * y_ratio);
  3979. }
  3980. im_tmp = gdImageCreate (dest_width, dest_height);
  3981. if (im_tmp == NULL ) {
  3982. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate temporary buffer");
  3983. RETURN_FALSE;
  3984. }
  3985. gdImageCopyResized (im_tmp, im_org, 0, 0, 0, 0, dest_width, dest_height, org_width, org_height);
  3986. gdImageDestroy(im_org);
  3987. fclose(org);
  3988. im_dest = gdImageCreate(dest_width, dest_height);
  3989. if (im_dest == NULL) {
  3990. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate destination buffer");
  3991. RETURN_FALSE;
  3992. }
  3993. white = gdImageColorAllocate(im_dest, 255, 255, 255);
  3994. if (white == -1) {
  3995. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
  3996. RETURN_FALSE;
  3997. }
  3998. black = gdImageColorAllocate(im_dest, 0, 0, 0);
  3999. if (black == -1) {
  4000. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate the colors for the destination buffer");
  4001. RETURN_FALSE;
  4002. }
  4003. int_threshold = int_threshold * 32;
  4004. for (y = 0; y < dest_height; y++) {
  4005. for (x = 0; x < dest_width; x++) {
  4006. color_org = gdImageGetPixel (im_tmp, x, y);
  4007. median = (im_tmp->red[color_org] + im_tmp->green[color_org] + im_tmp->blue[color_org]) / 3;
  4008. if (median < int_threshold) {
  4009. color = black;
  4010. } else {
  4011. color = white;
  4012. }
  4013. gdImageSetPixel (im_dest, x, y, color);
  4014. }
  4015. }
  4016. gdImageDestroy (im_tmp );
  4017. gdImageWBMP(im_dest, black , dest);
  4018. fflush(dest);
  4019. fclose(dest);
  4020. gdImageDestroy(im_dest);
  4021. RETURN_TRUE;
  4022. }
  4023. /* }}} */
  4024. #endif /* HAVE_GD_WBMP */
  4025. #endif /* HAVE_LIBGD */
  4026. /* Section Filters */
  4027. #define PHP_GD_SINGLE_RES \
  4028. zval *SIM; \
  4029. gdImagePtr im_src; \
  4030. if (zend_parse_parameters(1 TSRMLS_CC, "r", &SIM) == FAILURE) { \
  4031. RETURN_FALSE; \
  4032. } \
  4033. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); \
  4034. if (im_src == NULL) { \
  4035. RETURN_FALSE; \
  4036. }
  4037. static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
  4038. {
  4039. PHP_GD_SINGLE_RES
  4040. if (gdImageNegate(im_src) == 1) {
  4041. RETURN_TRUE;
  4042. }
  4043. RETURN_FALSE;
  4044. }
  4045. static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
  4046. {
  4047. PHP_GD_SINGLE_RES
  4048. if (gdImageGrayScale(im_src) == 1) {
  4049. RETURN_TRUE;
  4050. }
  4051. RETURN_FALSE;
  4052. }
  4053. static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
  4054. {
  4055. zval *SIM;
  4056. gdImagePtr im_src;
  4057. long brightness, tmp;
  4058. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
  4059. RETURN_FALSE;
  4060. }
  4061. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  4062. if (im_src == NULL) {
  4063. RETURN_FALSE;
  4064. }
  4065. if (gdImageBrightness(im_src, (int)brightness) == 1) {
  4066. RETURN_TRUE;
  4067. }
  4068. RETURN_FALSE;
  4069. }
  4070. static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
  4071. {
  4072. zval *SIM;
  4073. gdImagePtr im_src;
  4074. long contrast, tmp;
  4075. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
  4076. RETURN_FALSE;
  4077. }
  4078. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  4079. if (im_src == NULL) {
  4080. RETURN_FALSE;
  4081. }
  4082. if (gdImageContrast(im_src, (int)contrast) == 1) {
  4083. RETURN_TRUE;
  4084. }
  4085. RETURN_FALSE;
  4086. }
  4087. static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
  4088. {
  4089. zval *SIM;
  4090. gdImagePtr im_src;
  4091. long r,g,b,tmp;
  4092. long a = 0;
  4093. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) {
  4094. RETURN_FALSE;
  4095. }
  4096. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  4097. if (im_src == NULL) {
  4098. RETURN_FALSE;
  4099. }
  4100. if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
  4101. RETURN_TRUE;
  4102. }
  4103. RETURN_FALSE;
  4104. }
  4105. static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
  4106. {
  4107. PHP_GD_SINGLE_RES
  4108. if (gdImageEdgeDetectQuick(im_src) == 1) {
  4109. RETURN_TRUE;
  4110. }
  4111. RETURN_FALSE;
  4112. }
  4113. static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
  4114. {
  4115. PHP_GD_SINGLE_RES
  4116. if (gdImageEmboss(im_src) == 1) {
  4117. RETURN_TRUE;
  4118. }
  4119. RETURN_FALSE;
  4120. }
  4121. static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
  4122. {
  4123. PHP_GD_SINGLE_RES
  4124. if (gdImageGaussianBlur(im_src) == 1) {
  4125. RETURN_TRUE;
  4126. }
  4127. RETURN_FALSE;
  4128. }
  4129. static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS)
  4130. {
  4131. PHP_GD_SINGLE_RES
  4132. if (gdImageSelectiveBlur(im_src) == 1) {
  4133. RETURN_TRUE;
  4134. }
  4135. RETURN_FALSE;
  4136. }
  4137. static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS)
  4138. {
  4139. PHP_GD_SINGLE_RES
  4140. if (gdImageMeanRemoval(im_src) == 1) {
  4141. RETURN_TRUE;
  4142. }
  4143. RETURN_FALSE;
  4144. }
  4145. static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
  4146. {
  4147. zval *SIM;
  4148. long tmp;
  4149. gdImagePtr im_src;
  4150. double weight;
  4151. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
  4152. RETURN_FALSE;
  4153. }
  4154. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  4155. if (im_src == NULL) {
  4156. RETURN_FALSE;
  4157. }
  4158. if (gdImageSmooth(im_src, (float)weight)==1) {
  4159. RETURN_TRUE;
  4160. }
  4161. RETURN_FALSE;
  4162. }
  4163. static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS)
  4164. {
  4165. zval *IM;
  4166. gdImagePtr im;
  4167. long tmp, blocksize;
  4168. zend_bool mode = 0;
  4169. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll|b", &IM, &tmp, &blocksize, &mode) == FAILURE) {
  4170. RETURN_FALSE;
  4171. }
  4172. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  4173. if (im == NULL) {
  4174. RETURN_FALSE;
  4175. }
  4176. if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) {
  4177. RETURN_TRUE;
  4178. }
  4179. RETURN_FALSE;
  4180. }
  4181. /* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] )
  4182. Applies Filter an image using a custom angle */
  4183. PHP_FUNCTION(imagefilter)
  4184. {
  4185. zval *tmp;
  4186. typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
  4187. long filtertype;
  4188. image_filter filters[] =
  4189. {
  4190. php_image_filter_negate ,
  4191. php_image_filter_grayscale,
  4192. php_image_filter_brightness,
  4193. php_image_filter_contrast,
  4194. php_image_filter_colorize,
  4195. php_image_filter_edgedetect,
  4196. php_image_filter_emboss,
  4197. php_image_filter_gaussian_blur,
  4198. php_image_filter_selective_blur,
  4199. php_image_filter_mean_removal,
  4200. php_image_filter_smooth,
  4201. php_image_filter_pixelate
  4202. };
  4203. if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > IMAGE_FILTER_MAX_ARGS) {
  4204. WRONG_PARAM_COUNT;
  4205. } else if (zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) {
  4206. return;
  4207. }
  4208. if (filtertype >= 0 && filtertype <= IMAGE_FILTER_MAX) {
  4209. filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);
  4210. }
  4211. }
  4212. /* }}} */
  4213. /* {{{ proto resource imageconvolution(resource src_im, array matrix3x3, double div, double offset)
  4214. Apply a 3x3 convolution matrix, using coefficient div and offset */
  4215. PHP_FUNCTION(imageconvolution)
  4216. {
  4217. zval *SIM, *hash_matrix;
  4218. zval **var = NULL, **var2 = NULL;
  4219. gdImagePtr im_src = NULL;
  4220. double div, offset;
  4221. int nelem, i, j, res;
  4222. float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}};
  4223. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) {
  4224. RETURN_FALSE;
  4225. }
  4226. ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
  4227. nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix));
  4228. if (nelem != 3) {
  4229. php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
  4230. RETURN_FALSE;
  4231. }
  4232. for (i=0; i<3; i++) {
  4233. if (zend_hash_index_find(Z_ARRVAL_P(hash_matrix), (i), (void **) &var) == SUCCESS && Z_TYPE_PP(var) == IS_ARRAY) {
  4234. if (Z_TYPE_PP(var) != IS_ARRAY || zend_hash_num_elements(Z_ARRVAL_PP(var)) != 3 ) {
  4235. php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have 3x3 array");
  4236. RETURN_FALSE;
  4237. }
  4238. for (j=0; j<3; j++) {
  4239. if (zend_hash_index_find(Z_ARRVAL_PP(var), (j), (void **) &var2) == SUCCESS) {
  4240. SEPARATE_ZVAL(var2);
  4241. convert_to_double(*var2);
  4242. matrix[i][j] = Z_DVAL_PP(var2);
  4243. } else {
  4244. php_error_docref(NULL TSRMLS_CC, E_WARNING, "You must have a 3x3 matrix");
  4245. RETURN_FALSE;
  4246. }
  4247. }
  4248. }
  4249. }
  4250. res = gdImageConvolution(im_src, matrix, div, offset);
  4251. if (res) {
  4252. RETURN_TRUE;
  4253. } else {
  4254. RETURN_FALSE;
  4255. }
  4256. }
  4257. /* }}} */
  4258. /* End section: Filters */
  4259. #ifdef HAVE_GD_BUNDLED
  4260. /* {{{ proto bool imageantialias(resource im, bool on)
  4261. Should antialiased functions used or not*/
  4262. PHP_FUNCTION(imageantialias)
  4263. {
  4264. zval *IM;
  4265. zend_bool alias;
  4266. gdImagePtr im;
  4267. if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &IM, &alias) == FAILURE) {
  4268. return;
  4269. }
  4270. ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
  4271. gdImageAntialias(im, alias);
  4272. RETURN_TRUE;
  4273. }
  4274. /* }}} */
  4275. #endif
  4276. /*
  4277. * Local variables:
  4278. * tab-width: 4
  4279. * c-basic-offset: 4
  4280. * End:
  4281. * vim600: sw=4 ts=4 fdm=marker
  4282. * vim<600: sw=4 ts=4
  4283. */