手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:php

利用imageMagicK制作有背景色的缩略图

原文如下:附本人翻译(翻译水平其差,可以忽略直接看英文)

原文网址:http://valokuva.org/?p=92
  1. I know, it's been a while since I last blogged. This is because a lot of things are happening in my personal life. I recently relocated to London from Finland and started a new job. Things are quite busy but I will try to post an example now and then. In the meanwhile I would like to hear about sites using Imagick, so if your project is not super secret please post an url and maybe a small explanation what you're doing with Imagick on the site. This is purely for my personal interest.
  2. Anyway, to the point. Today's example originates from a question asked by a user. How do I thumbnail the image inside given dimensions proportionally and fill the "blank" areas with a color? Well, the answer is here :)
  3. The code is for Imagick 2.1.0 but adapting to older versions should not be hard.

 

翻译如下:

我知道现在离我的博客更新有一段时间了,这主要是因为最近发生了很多事。最近我找了份新工作,使我从芬兰搬到了伦敦,工作也非常忙,所以我在这里仅仅只发一个示例。同时我很高兴听到很多网站使用了imagick,我也希望如果您的项目不是很保密的话,是否能够发个链接及少量的注释以说明您的站点是如何使用Imagek的。顺便说一声,这完全是我个人的兴趣。

OK,上重头菜。今天的例子起源于一个用户的问题,那就是如果在为一张图片按比例做缩略图的时候,怎么为留空的地方用其他颜色填充。这个例子就是我的回复。

代码是FOR ImagicK 2.1.0版本,当然要改成以前的老版本代码也不是件难事。

下面就是代码了:

PHP代码
  1. <?php  
  2. /* Define width and height of the thumbnail */ 
  3. /* 定义缩略图的长宽*/
  4. $width = 100;  
  5. $height = 100; 

  6. /* Instanciate and read the image in */ 
  7. /*创建一个对象,同时读回源图*/
  8. $im = new Imagick( "test.png" );  
  9. /* Fit the image into $width x $height box 
  10. The third parameter fits the image into a "bounding box" */ 
  11. /*按照比例进行缩放*/
  12. $im->thumbnailImage( $width$height, true );  
  13. /* 按照缩略图大小创建一个有颜色的图片 */  
  14. $canvas = new Imagick();  
  15. $canvas->newImage( $width$height'pink''png' );  
  16. /* 取得缩图的实际大小 */  
  17. $geometry = $im->getImageGeometry();  
  18. /* 计算高度 */  
  19. $x = ( $width - $geometry['width'] ) / 2;  
  20. $y = ( $height - $geometry['height'] ) / 2;  
  21. /* 合并图片  */  
  22. $canvas->compositeImage( $im, imagick::COMPOSITE_OVER, $x$y );  
  23. /* 输出图片*/  
  24. header( "Content-Type: image/png" );  
  25. echo $canvas;  
  26. ?>  

 膘叔,上图片

源图:

大小: 320.67 K
尺寸: 300 x 198
浏览: 1621 次
点击打开新窗口浏览全图

缩图:

大小: 35.55 K
尺寸: 100 x 100
浏览: 1669 次
点击打开新窗口浏览全图

 

Tags: php, imagemagick, magicwand, thumbnail

PHP5.30的更新列表

啥也不说了。自己看列表吧。。原来,更新了这么多啊。。。。。。现在还是alpha,等到了stable,那我应该不应该更新呢》》》

更新列表(请看第44行哦)
  1. PHP NEWS  
  2. |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  
  3. ?? ??? 200?, PHP 5.3.0 Alpha 2  
  4. - Removed shebang line check from CGI sapi (it is checked by scanner) (Dmitry)  
  5.   
  6. - Fixed bug #45696 (Not all DateTime methods allow method chaining). (Derick)  
  7. - Fixed bug #45545 (DateInterval has a limitation of 4 chars for ISO  
  8. durations). (Derick)  
  9. - Fixed bug #45406 (session.serialize_handler declared by shared extension  
  10. fails). (Kalle, oleg dot grenrus at dynamoid dot com)  
  11. - Fixed bug #44100 (Inconsistent handling of static array declarations with  
  12. duplicate keys). (Dmitry)  
  13. - Fixed bug #43008 (php://filter uris ignore url encoded filternames and can't  
  14. handle slashes). (Arnaud)  
  15.   
  16. 01 Aug 2008, PHP 5.3.0 Alpha 1  
  17. - Upgraded bundled PCRE to version 7.7. (Nuno)  
  18. - Upgraded bundled PDO sqlite to version 3.5.9. (Scott)  
  19.   
  20. - Moved extensions to PECL (Pierre):  
  21. . ext/fdf  
  22. . ext/ncurses  
  23. . ext/sybase (not maintained anymore, sybase_ct has to be used instead)  
  24.   
  25. - Removed the experimental RPL (master/slave) functions from mysqli. (Andrey)  
  26. - Removed zend.ze1_compatibility_mode. (Dmitry)  
  27. - Deprecated ticks support. (Felipe)  
  28.   
  29. - Changed PCRE, Reflection and SPL extensions to be always enabled. (Marcus)  
  30. - Changed md5() to use improved implementation. (Solar Designer, Dmitry)  
  31. - Changed HTTP stream wrapper to accept any code between and including  
  32. 200 to 399 as successful. (Mike, Noah Fontes)  
  33.   
  34. - Improved PHP syntax and semantics:  
  35. . Added lambda functions and closures. (Christian Seiler, Dmitry)  
  36. . Added "jump label" operator (limited "goto"). (Dmitry, Sara)  
  37. . Added NOWDOC syntax. (Gwynne Raskind, Stas, Dmitry)  
  38. . Added HEREDOC syntax with double quotes. (Lars Strojny, Felipe)  
  39. . Added support for using static HEREDOCs to initialize static variables and  
  40. class members or constants. (Matt)  
  41. . Improved syntax highlighting and consistency for variables in double-quoted  
  42. strings and literal text in HEREDOCs and backticks. (Matt)  
  43. . Added "?:" operator. (Marcus)  
  44. . Added support for namespaces. (Dmitry, Stas, Gregory)  
  45. . Added support for Late Static Binding. (Dmitry, Etienne Kneuss)  
  46. . Added support for __callStatic() magic method. (Sara)  
  47. . Added forward_static_call(_array) to complete LSB. (Mike Lively)  
  48. . Added support for dynamic access of static members using $foo::myFunc().  
  49. (Etienne Kneuss)  
  50. . Improved checks for callbacks. (Marcus)  
  51. . Added __DIR__ constant. (Lars Strojny)  
  52. . Added PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION,  
  53. PHP_EXTRA_VERSION, PHP_VERSION_ID, PHP_ZTS and PHP_DEBUG constants.  
  54. (Pierre)  
  55. . Added new error modes E_USER_DEPRECATED and E_DEPRECATED.  
  56. E_DEPRECATED is used to inform about stuff being scheduled for removal  
  57. in future PHP versions. (Lars Strojny, Felipe, Marcus)  
  58. . Added "request_order" INI variable to control specifically $_REQUEST  
  59. behavior. (Stas)  
  60. . Added support for exception linking. (Marcus)  
  61. . Added ability to handle exceptions in destructors. (Marcus)  
  62.   
  63. - Improved PHP runtime speed and memory usage:  
  64. . Substitute persistent constants by their values at compile time. (Matt)  
  65. . Optimized ZEND_SIGNED_MULTIPLY_LONG(). (Matt)  
  66. . Removed direct executor recursion. (Dmitry)  
  67. . Use fastcall calling convention in executor on x86. (Dmitry)  
  68. . Use IS_CV for direct access to $this variable. (Dmitry)  
  69. . Use ZEND_FREE() opcode instead of ZEND_SWITCH_FREE(IS_TMP_VAR). (Dmitry)  
  70. . Lazy EG(active_symbol_table) initialization. (Dmitry)  
  71. . Optimized ZEND_RETURN opcode to not allocate and copy return value if it is  
  72. not used. (Dmitry)  
  73. . Replaced all flex based scanners with re2c based scanners.  
  74. (Marcus, Nuno, Scott)  
  75. . Added garbage collector. (David Wang, Dmitry).  
  76. . Improved PHP binary size and startup speed with GCC4 visibility control.  
  77. (Nuno)  
  78. . Improved engine stack implementation for better performance and stability.  
  79. (Dmitry)  
  80. . Improved memory usage by moving constants to read only memory.  
  81. (Dmitry, Pierre)  
  82. . Changed exception handling. Now each op_array doesn't contain  
  83. ZEND_HANDLE_EXCEPTION opcode in the end. (Dmitry)  
  84. . Optimized require_once() and include_once() by eliminating fopen(3) on  
  85. second usage. (Dmitry)  
  86. . Optimized ZEND_FETCH_CLASS + ZEND_ADD_INTERFACE into single  
  87. ZEND_ADD_INTERFACE opcode. (Dmitry)  
  88. . Optimized string searching for a single character.  
  89. (Michal Dziemianko, Scott)  
  90. . Optimized interpolated strings to use one less opcode. (Matt)  
  91.   
  92. - Improved php.ini handling: (Jani)  
  93. . Added ".htaccess" style user-defined php.ini files support for CGI/FastCGI.  
  94. . Added support for special [PATH=/opt/httpd/www.example.com/] and  
  95. [HOST=www.example.com] sections. Directives set in these sections can  
  96. not be overridden by user-defined ini-files or during runtime.  
  97. . Added better error reporting for php.ini syntax errors.  
  98. . Allowed using full path to load modules using "extension" directive.  
  99. . Allowed "ini-variables" to be used almost everywhere ini php.ini files.  
  100. . Allowed using alphanumeric/variable indexes in "array" ini options.  
  101. . Added 3rd optional parameter to parse_ini_file() to specify the scanning  
  102. mode of INI_SCANNER_NORMAL or INI_SCANNER_RAW. In raw mode option values  
  103. and section values are treated as-is.  
  104. . Fixed get_cfg_var() to be able to return "array" ini options.  
  105. . Added optional parameter to ini_get_all() to only retrieve the current  
  106. value. (Hannes)  
  107.   
  108. - Improved and cleaned CGI code:  
  109. . FastCGI is now always enabled and can not be disabled.  
  110. See sapi/cgi/CHANGES for more details. (Dmitry)  
  111. . Added CGI SAPI -T option which can be used to measure execution  
  112. time of script repeated several times. (Dmitry)  
  113.   
  114. - Improved streams:  
  115. . Fixed confusing error message on failure when no errors are logged. (Greg)  
  116. . Added stream_supports_lock() function. (Benjamin Schulz)  
  117. . Added "ignore_errors" option to http fopen wrapper. (David Zulke, Sara)  
  118. . Added context parameter for copy() function. (Sara)  
  119. . Added "glob://" stream wrapper. (Marcus)  
  120. . Added "params" as optional parameter for stream_context_create(). (Sara)  
  121. . Added ability to use stream wrappers in include_path. (Gregory, Dmitry)  
  122.   
  123. - Improved hash extension:  
  124. . Changed mhash to be a wrapper layer around the hash extension. (Scott)  
  125. . Added hash_copy() function. (Tony)  
  126. . Added sha224 hash algorithm to the hash extension. (Scott)  
  127.   
  128. - Improved mbstring extension:  
  129. . Added "mbstring.http_output_conv_mimetypes" INI directive that allows  
  130. common non-text types such as "application/xhtml+xml" to be converted  
  131. by mb_output_handler(). (Moriyoshi)  
  132.   
  133. - Improved OCI8 extension (Chris Jones/Oracle Corp.):  
  134. . Added Database Resident Connection Pooling (DRCP) and Fast  
  135. Application Notification (FAN) support.  
  136. . Added support for Oracle External Authentication (not supported  
  137. on Windows).  
  138. . Improve persistent connection handling of restarted DBs.  
  139. . Added SQLT_AFC (aka CHAR datatype) support to oci_bind_by_name.  
  140. . Fixed bug #41069 (Seg fault with query over DB link).  
  141. . Fixed define of SQLT_BDOUBLE and SQLT_BFLOAT constants with Oracle  
  142. 10g ORACLE_HOME builds.  
  143. . Changed default value of oci8.default_prefetch from 10 to 100.  
  144. . Fixed PECL bug #12431 (OCI8 ping functionality is broken).  
  145. . Allow building (e.g from PECL) the PHP 5.3-based OCI8 code with  
  146. PHP 4.3.9 onwards.  
  147.   
  148. - Improved OpenSSL extension: (Dmitry)  
  149. . Added support for OpenSSL digest and cipher functions.  
  150. . Added access to internal values of DSA, RSA and DH keys.  
  151.   
  152. - Improved pcntl extension: (Arnaud)  
  153. . Added pcntl_signal_dispatch().  
  154. . Added pcntl_sigprocmask().  
  155. . Added pcntl_sigwaitinfo().  
  156. . Added pcntl_sigtimedwait().  
  157.   
  158. - Improved SOAP extension:  
  159. . Added support for element names in context of XMLShema's <any>. (Dmitry)  
  160. . Added ability to use Traversable objects instead of plain arrays.  
  161. (Joshua Reese, Dmitry)  
  162. . Fixed possible crash bug caused by an uninitialized value. (Zdash Urf)  
  163.   
  164. - Improved SPL extension:  
  165. . Added SPL to list of standard extensions that cannot be disabled. (Marcus)  
  166. . Added ability to store associative information with objects in  
  167. SplObjectStorage. (Marcus)  
  168. . Added ArrayAccess support to SplObjectStorage. (Marcus)  
  169. . Added SplDoublyLinkedList, SplStack, SplQueue classes. (Etienne)  
  170. . Added FilesystemIterator. (Marcus)  
  171. . Added GlobIterator. (Marcus)  
  172. . Added SplHeap, SplMinHeap, SplMaxHeap, SplPriorityQueue classes. (Etienne)  
  173. . Added new parameter $prepend to spl_autoload_register(). (Etienne)  
  174. . Added FixedArray. (Etienne, Tony)  
  175. . Added delaying exceptions in SPL's autoload mechanism. (Marcus)  
  176. . Added RecursiveTreeIterator. (Arnaud, Marcus)  
  177. . Added MultipleIterator. (Arnaud, Marcus, Johannes)  
  178.   
  179. - Improved Zend Engine:  
  180. . Added "compact" handler for Zend MM storage. (Dmitry)  
  181. . Added "+" and "*" specifiers to zend_parse_parameters(). (Andrei)  
  182. . Added concept of "delayed early binding" that allows opcode caches to  
  183. perform class declaration (early and/or run-time binding) in exactly  
  184. the same order as vanilla PHP. (Dmitry)  
  185.   
  186. - Improved crypt() function: (Pierre)  
  187. . Added Blowfish and extended DES support. (Using Blowfish implementation  
  188. from Solar Designer).  
  189. . Made crypt features portable by providing our own implementations  
  190. for crypt_r and the algorithms which are used when OS does not provide  
  191. them. PHP implementations are always used for Windows builds.  
  192.   
  193. - Added new extensions:  
  194. . Added fileinfo extension as replacement for mime_magic extension. (Derick)  
  195. . Added intl extension for Internationalization. (Ed B., Vladimir I.,  
  196. Dmitry L., Stanislav M., Vadim S., Kirti V.)  
  197. . Added mysqlnd extension as replacement for libmysql for ext/mysql, mysqli  
  198. and PDO_mysql. (Andrey, Johannes, Ulf)  
  199. . Added phar extension for handling PHP Archives. (Greg, Marcus, Steph)  
  200. . Added SQLite3 extension. (Scott)  
  201.   
  202. - Added new date/time functionality: (Derick)  
  203. . date_parse_from_format(): Parse date/time strings according to a format.  
  204. . date_create_from_format()/DateTime::createFromFormat(): Create a date/time  
  205. object by parsing a date/time string according to a given format.  
  206. . date_get_last_errors()/DateTime::getLastErrors(): Return a list of warnings  
  207. and errors that were found while parsing a date/time string through:  
  208. . strtotime() / new DateTime  
  209. . date_create_from_format() / DateTime::createFromFormat()  
  210. . date_parse_from_format().  
  211. . support for abbreviation and offset based timezone specifiers for  
  212. DateTime::getOffset() and DateTime::getName().  
  213. . support for selectively listing timezone identifiers by continent or  
  214. country code through timezone_identifiers_list() /  
  215. DateTimezone::listIdentifiers().  
  216. . timezone_location_get() / DateTimezone::getLocation() for retrieving  
  217. location information from timezones.  
  218. . date_timestamp_set() / DateTime::setTimestamp() to set a Unix timestamp  
  219. without invoking the date parser. (Scott, Derick)  
  220. . date_timestamp_get() / DateTime::getTimestamp() to retrieve the Unix  
  221. timestamp belonging to a date object.  
  222. . two optional parameters to timezone_transitions_get() /  
  223. DateTimeZone::getTranstions() to limit the range of transitions being  
  224. returned.  
  225. . support for "first/last day of <month>" style texts.  
  226. . support for date/time strings returned by MS SQL.  
  227. . support for serialization and unserialization of DateTime objects.  
  228. . support for diffing date/times through date_diff() / DateTime::diff().  
  229. . support for adding/subtracting weekdays with strtotime() and  
  230. DateTime::modify().  
  231. . DateInterval class to represent the difference between two date/times.  
  232. . support for parsing ISO intervals for use with DateInterval.  
  233. . date_add() / DateTime::add(), date_sub() / DateTime::sub() for applying an  
  234. interval to an existing date/time.  
  235. . proper support for "this week", "previous week"/"last week" and "next week"  
  236. phrases so that they actually mean the week and not a seven day period  
  237. around the current day.  
  238. . support for "<xth> <weekday of" and "last <weekday> of" phrases to be used  
  239. with months - like in "last saturday of februari 2008".  
  240. . DatePeriod class which supports iterating over a DateTime object applying  
  241. DateInterval on each iteration, up to an end date or limited by maximum  
  242. number of occurences.  
  243.   
  244. - Added array_replace() and array_replace_recursive() functions. (Matt)  
  245. - Added ReflectionProperty::setAccessible() method that allows non-public  
  246. property's values to be read through ::getValue(). (Derick)  
  247. - Added msg_queue_exists() function to sysvmsg extension. (Benjamin Schulz)  
  248. - Added Firebird specific attributes that can be set via PDO::setAttribute()  
  249. to control formatting of date/timestamp columns: PDO::FB_ATTR_DATE_FORMAT,  
  250. PDO::FB_ATTR_TIME_FORMAT and PDO::FB_ATTR_TIMESTAMP_FORMAT. (Lars W)  
  251. - Added gmp_testbit() function. (Stas)  
  252. - Added icon format support to getimagesize(). (Scott)  
  253. - Added LDAP_OPT_NETWORK_TIMEOUT option for ldap_set_option() to allow  
  254. setting network timeout (FR #42837). (Jani)  
  255. - Added optional escape character parameter to fgetcsv(). (David Soria Parra)  
  256. - Added an optional parameter to strstr() and stristr() for retrieval of either  
  257. the part of haystack before or after first occurrence of needle.  
  258. (Johannes, Felipe)  
  259. - Added xsl->setProfiling() for profiling stylesheets. (Christian)  
  260. - Added long-option feature to getopt() and made getopt() available also on  
  261. win32 systems by adding a common getopt implementation into core.  
  262. (David Soria Parra, Jani)  
  263. - Added support for optional values, and = as separator, in getopt(). (Hannes)  
  264. - Added lcfirst() function. (David C)  
  265. - Added PREG_BAD_UTF8_OFFSET_ERROR constant. (Nuno)  
  266. - Added native support for asinh(), acosh(), atanh(), log1p() and expm1().  
  267. (Kalle)  
  268. - Added inet_pton() and inet_ntop() also for Windows platforms. (Kalle)  
  269. - Added mcrypt_create_iv() also for Windows platforms. (Pierre)  
  270.   
  271. - Fixed html_entity_decode() incorrectly converting numeric html entities  
  272. to different characters with cp1251 and cp866. (Scott)  
  273. - Fixed an issue in date() where a : was printed for the O modifier after a P  
  274. modifier was used. (Derick)  
  275. - Fixed exec() on Windows to not eat the first and last double quotes. (Scott)  
  276.   
  277. - Fixed PECL bug #12794 (PDOStatement->nextRowset() doesn�t work). (Johannes)  
  278. - Fixed PECL bug #12401 (Add support for ATTR_FETCH_TABLE_NAMES). (Johannes)  
  279.   
  280. - Fixed bug #45622 (isset($arrayObject->p) misbehaves with ArrayObject::  
  281. ARRAY_AS_PROPS set). (robin_fernandes at uk dot ibm dot com, Arnaud)  
  282. - Fixed bug #45614 (ArrayIterator::current(), ::key() can show 1st private  
  283. prop of wrapped object). (robin_fernandes at uk dot ibm dot com, Arnaud)  
  284. - Fixed bug #45571 (ReflectionClass::export() shows superclasses' private  
  285. static methods). (robin_fernandes at uk dot ibm dot com)  
  286. - Fixed bug #45540 (stream_context_create creates bad http request). (Arnaud)  
  287. - Fixed bug #45430 (windows implementation of crypt is not thread safe).  
  288. (Pierre)  
  289. - Fixed bug #45345 (SPLFileInfo::getPathInfo() returning dir info instead of  
  290. file info). (Etienne)  
  291. - Fixed bug #45179 (--with-mysql-sock fails to compile & work). (Andrey)  
  292. - Fixed bug #45038 (Crash when using DateTimeZone object returned by  
  293. Date::getTimezone). (Joe Orton, Derick)  
  294. - Fixed bug #44769 (declaring private magic methods should throw error).  
  295. (Felipe)  
  296. - Fixed bug #44913 (Segfault when using return in combination with nested loops  
  297. and continue 2). (Dmitry)  
  298. - Fixed bug #44899 (__isset usage changes behavior of empty()). (Etienne)  
  299. - Fixed bug #44897 (failed to prepare statement). (Andrey)  
  300. - Fixed bug #44849 (imagecolorclosesthwb() is not available on Windows).  
  301. (Kalle)  
  302. - Fixed bug #44805 (rename() function is not portable to Windows). (Pierre)  
  303. - Fixed bug #44779 (filter returns NULL in CLI when it shouldn't). (Arnaud)  
  304. - Fixed bug #44742 (timezone_offset_get() causes segmentation faults). (Derick)  
  305. - Fixed bug #44660 (Indexed and reference assignment to propery of non-object  
  306. don't trigger warning). (Dmitry)  
  307. - Fixed bug #44648 (Attribute names not checked for wellformedness). (Rob)  
  308. - Fixed bug #44414 (Incomplete reporting about abstract methods). (Dmitry)  
  309. - Fixed bug #44390 (mysqli_bind_param/bind_result and Object member variables).  
  310. (Andrey)  
  311. - Fixed bug #44352 (mysqli_connect_error() false negative for host errors).  
  312. (Andrey)  
  313. - Fixed bug #44336 (Improve pcre UTF-8 string matching performance).  
  314. (frode at coretrek dot com, Nuno)  
  315. - Fixed bug #44301 (Segfault when an exception is thrown on persistent  
  316. connections). (Martin Jansen)  
  317. - Fixed bug #44257 (timelib_tz_lookup_table must use float for gmtoffset).  
  318. (Derick, iuri dot fiedoruk at hp dot com).  
  319. - Fixed bug #44214 (Crash using preg_replace_callback() and global variable).  
  320. (Nuno, Scott)  
  321. - Fixed bug #44034 (FILE_IGNORE_NEW_LINES in file() does not work as expected  
  322. when lines end in \r\n). (Ilia)  
  323. - Fixed bug #43960 (strtotime() returns timestamp in the future when given a  
  324. bogus string). (Derick)  
  325. - Fixed bug #43832 (mysqli_get_charset() doesn't expose charset comment).  
  326. (Andrey)  
  327. - Fixed bug #43808 (date_create never fails (even when it should)). (Derick)  
  328. - Fixed bug #43527 (DateTime created from a timestamp reports environment  
  329. timezone). (Derick)  
  330. - Fixed bug #43452 (strings containing a weekday, or a number plus weekday  
  331. misbehaved if the current day-of-week was same as the one in the phrase).  
  332. (Derick)  
  333. - Fixed bug #43426 (crash on nested call_user_func() calls). (Dmitry)  
  334. - Fixed bug #43323 (Wrong count abstract methods). (Felipe, Dmitry)  
  335. - Fixed bug #43261 (Use ^ as the escape with escapeshellcmd() on Windows).  
  336. (Scott)  
  337. - Fixed bug #43075 (Support 2007-11-01T24:00:00+00:00). (Derick)  
  338. - Fixed bug #43003 (Invalid timezone reported for DateTime objects constructed  
  339. using a timestamp). (Derick)  
  340. - Fixed bug #43143 (Warning about empty IV with MCRYPT_MODE_ECB). (Derick)  
  341. - Fixed bug #43136 (possible crash on script execution timeout.  
  342. The EG(function_state_ptr) is completely removed,  
  343. EG(current_execute_data)->function_state must be used instead). (Dmitry)  
  344. - Fixed bug #42952 (soap cache file is created with insecure permissions).  
  345. (Dmitry)  
  346. - Fixed bug #42868 (Floats cast to integer produce unpredictable results).  
  347. (Zoe Slattery)  
  348. - Fixed bug #42848 (Status: header incorrect under FastCGI). (Dmitry)  
  349. - Fixed bug #42773 (WSDL error causes HTTP 500 Response). (Dmitry)  
  350. - Fixed bug #42737 (preg_split('//u') triggers a E_NOTICE with newlines).  
  351. (Nuno)  
  352. - Fixed bug #42736 (xmlrpc_server_call_method() crashes). (Tony)  
  353. - Fixed bug #42663 (gzinflate() try to allocate all memory with truncated  
  354. data). (Arnaud)  
  355. - Fixed bug #42657 (ini_get() returns incorrect value when default is NULL).  
  356. (Jani, Scott)  
  357. - Fixed bug #42637 (SoapFault : Only http and https are allowed). (Bill Moran)  
  358. - Fixed bug #42548 (mysqli PROCEDURE calls can't return result sets). (Hartmut)  
  359. - Fixed bug #42509 (gmp leaks memory when gmp_init() not used). (Stas)  
  360. - Fixed bug #42499 (PDO_MYSQL: multi-statement execution via PDO::exec() makes  
  361. connection unusable). (Johannes)  
  362. - Fixed bug #42443 (PDO SQLite driver binds integers and booleans as strings).  
  363. (Scott)  
  364. - Fixed bug #42284 (duplicate of #39700). (Lars W)  
  365. - Fixed bug #42203 (Clear SQLite result sets before closing database). (Scott)  
  366. - Fixed bug #42190 (Constructing DateTime with TimeZone Indicator invalidates  
  367. DateTimeZone). (Derick)  
  368. - Fixed bug #42069 (parse_ini_file() allows using some non-alpha numeric  
  369. characters). (Jani)  
  370. - Fixed bug #41997 (pdo_mysql: stored procedure call returning single rowset  
  371. blocks future queries). (Johannes)  
  372. - Fixed bug #41996 (Problem accessing Oracle ROWID). (Martin Jansen)  
  373. - Fixed bug #41599 (setTime() fails after modify() is used). (Derick)  
  374. - Fixed bug #41522 (PDO firebird driver returns null if it fails to connect).  
  375. (Lars W)  
  376. - Fixed bug #41135 (PDO SQLite driver binds blobs as strings,  
  377. use sqlite3_bind_blob() to stop errors with null bytes). (Scott)  
  378. - Fixed bug #39822 (new PDO() doesn't work with firebird). (Lars W)  
  379. - Fixed bug #39700 (NUMERIC error when result precision are 7,8 or 12-14 ).  
  380. (Lars W)  
  381. - Fixed bug #39457 (Multiple invoked OO connections never close). (Andrey)  
  382. - Fixed bug #39397 (invalid statement handle in Unknown on line 0). (Lars W)  
  383. - Fixed bug #39346 (Unsetting a static variable inside a destructor causes  
  384. segfault later on). (Dmitry)  
  385. - Fixed bug #39127 (Old-style constructor fallbacks produce strange results).  
  386. (Tony)  
  387. - Fixed bug #39056 (Interbase NUMERIC data type error). (Lars W)  
  388. - Fixed bug #39018 (Error control operator '@' fails to suppress "Uninitialized  
  389. string offset"). (Felipe)  
  390. - Fixed bug #38468 (Unexpected creation of cycle). (Dmitry)  
  391. - Fixed bug #37964 (Reflection shows private methods of parent class).  
  392. (Felipe, Marcus)  
  393. - Fixed bug #37911 (preg_replace_callback() ignores named groups). (Nuno)  
  394. - Fixed bug #37076 (SimpleXML ignores .=). (Felipe, Marcus)  
  395. - Fixed bug #36128 (Interbase PDO - timestamp columns return NULL). (Lars W)  
  396. - Fixed bug #35386 (firebird: first row is null). (Lars W)  
  397. - Fixed bug #35163 (Array elements can lose references). (Dmitry)  
  398. - Fixed bug #32330 (session_destroy, "Failed to initialize storage module",  
  399. custom session handler). (Gwynne)  
  400. - Fixed bug #32143 (ibase_query() causing IBserver 7 crash with NULL param as  
  401. link-id). (Lars W)  
  402. - Fixed bug #30907 (ibase_query() crashes (same bug as #32143). (Lars W)  
  403. - Fixed bug #30690 (Resource handle from ibase_execute becomes invalid after  
  404. return). (Lars W)  
  405. - Fixed bug #29044 (compact() does not have infinite recursion protection).  
  406. (Tony)  
  407. - Fixed bug #27372 (parse error loading browscap.ini at apache startup).  
  408. (Jani)   

Tags: php, upgrade, namespace

IIS 6 下的 PHP 最佳配置方法

虽然 LAMP 组合很不错,但是如果想要架设一台同时支持 PHP、ASP、ASP.NET、JSP、Perl 的 Web 虚拟主机服务器,还是用 Windows 2003 的 IIS 6 最好。网上有很多介绍在 IIS 6 上配置 PHP 的文章,但是那些方法不是性能不好,就是升级麻烦。下面的方法可以让你在第一次配置好后,能够非常方便的进行升级。

这里所说的升级,是指从某个 php4 版本升级到另一个 php4 版本,或者从某个 php5 版本升级到另一个 php5 版本,而不是指从 php4 升级到 php5。

准备:

一台安装好的 Windows 2003 服务器,并且已经安装了 IIS 6。

下载 Windows 版的 PHP 二进制压缩包

安装:

解压缩 PHP 二进制压缩包到 C:\php 目录下(这里假设 C: 盘是系统盘,即安装了Windows 系统的盘,如果系统盘是 D: 盘,则解压缩到 D:\php 目录下,以此类推,下同)。

然后打开“我的电脑”->“属性”->“高级”->“环境变量”->“系统变量”->“path”,编辑其值,在前面增加下面的路径地址:

C:\php;C:\php\dlls;C:\php\extensions;C:\php\sapi;

将 php.ini-dist 或 php.ini-recommended 复制到 C:\Windows 目录下,并改名为 php.ini,一般正式发布网站的服务器用 php.ini-dist,而作为调试用的服务器用 php.ini-recommended 更好。当然一般情况下,这个 php.ini 还是需要根据实际情况来修改的。

下面来介绍一下几个必要的修改选项:

extension_dir = "C:\php\extensions"

这个是 PHP 扩展所放置的目录,请确保跟你实际安装的目录相同。

PHP常用扩展
  1. extension=php_mbstring.dll  
  2. ;extension=php_big_int.dll  
  3. extension=php_bz2.dll  
  4. extension=php_cpdf.dll  
  5. extension=php_crack.dll  
  6. extension=php_curl.dll  
  7. extension=php_db.dll  
  8. extension=php_dba.dll  
  9. extension=php_dbase.dll  
  10. extension=php_dbx.dll  
  11. extension=php_domxml.dll  
  12. ;extension=php_exif.dll  
  13. ;extension=php_fdf.dll  
  14. ;extension=php_filepro.dll  
  15. extension=php_gd2.dll  
  16. extension=php_gettext.dll  
  17. extension=php_hyperwave.dll  
  18. extension=php_iconv.dll  
  19. ;extension=php_ifx.dll  
  20. ;extension=php_iisfunc.dll  
  21. extension=php_imap.dll  
  22. ;extension=php_interbase.dll  
  23. extension=php_java.dll  
  24. extension=php_ldap.dll  
  25. ;extension=php_mcrypt.dll  
  26. extension=php_mhash.dll  
  27. extension=php_mime_magic.dll  
  28. extension=php_ming.dll  
  29. extension=php_mssql.dll  
  30. extension=php_msql.dll  
  31. ;extension=php_oci8.dll  
  32. extension=php_openssl.dll  
  33. ;extension=php_oracle.dll  
  34. extension=php_pdf.dll  
  35. extension=php_pgsql.dll  
  36. ;extension=php_printer.dll  
  37. extension=php_shmop.dll  
  38. ;extension=php_snmp.dll  
  39. extension=php_sockets.dll  
  40. ;extension=php_sybase_ct.dll  
  41. extension=php_w32api.dll  
  42. extension=php_xmlrpc.dll  
  43. extension=php_xslt.dll  
  44. extension=php_yaz.dll  
  45. extension=php_zip.dll  

上面这些,开头没有加分号的是打开的扩展,加了分号的是没有打开的扩展。上面的设置包含了在 Windows 2003 上默认安装情况下可以打开所有扩展(这里列出的是 php 4 的)。

session.save_path = b:\sessions

这个是 session 文件默认保存的目录,这个目录必须是一个存在的目录,不然默认的 session 功能会无效。我这里设置的是一个 ramdisk 上的一个目录。将 session.save_path 设置在 ramdisk 上可以加快 session 处理的速度。如果你没有安装 ramdisk,你可以把它指定到其他盘的任何一个目录下,如 C:\sessions 目录、C:\Windows\Temp 目录等。

OK,基本工作作完了,现在该配置 IIS 了。

打开“ Internet 信息服务(IIS)管理器”,在“ Web 服务扩展”里,选择“添加一个新的 Web 服务扩展”,扩展名可填写“PHP ISAPI 扩展”,要求的文件选择:C:\php\sapi\php4isapi.dll(如果安装的是 PHP5,则此处是 C:\php\sapi\php5isapi.dll,下同),并设置扩展状态为允许。

打开“网站”->“属性”->“主目录”->“应用程序设置”->“配置”->“应用程序扩展”->“添加 ”,可执行文件还是选择 C:\php\sapi\php4isapi.dll。扩展名填写“.php”,动作限制为“HEAD,GET,POST”。

打开“网站”->“属性”->“文档”->“启用默认内容文档”->“添加”,可以将 index.php 添加为默认内容文档。

然后选择“服务器机器名”->“所有任务”->“重新启动 IIS”来重启 IIS。

测试

在默认网站发布目录下,建立一个测试页面:

PHP代码
  1. <?php  
  2. phpinfo();  
  3. ?> 

 

如果打开这个页面能够看到 php 安装配置信息,就算是安装成功了。

如果想要更优化的执行 php 程序,可以安装 ZendOptimizer-3.0.1-Windows-i386.exe,这个东西安装非常简单,这里就不介绍了。

升级

现在升级就非常简单了。只需要将新版本的 PHP 二进制压缩包下载下来,将原来的 C:\php 目录删除,将新版本解压缩到 C:\php 目录中,然后重新启动一下 IIS 就可以了。不需要修改任何配置,也不需要往 System32 目录中复制任何文件。是不是很方便啊?


膘叔的小技巧:
由于在IIS下面建立站点和关闭站点都比较方便,但是象上面说的升级就不是很方便了。我是指启用站点,虽然直接点击控制台上的restart按钮很方便,但。。。WINDOWS有时候会突然卡死,那时候是关也不能关,开也不能开,只能注销,在这里,我提供一个小小的批处理文件,只要放在桌面上,想重启的时候运行一下就行了。。
文件内容如下:

XML/HTML代码
  1. net stop w3svc  
  2. net start w3svc  

是不是很简单?但不要小看这两行,WINDOWS好象是对命令行的处理有一定的优先级,而且用命令行不会被卡死。

 

Tags: iis, php, setup, config

关于 PHP 中的 iconv 函数的一点小问题[转]

作者:andot,来自:www.coolcode.cn,出处:http://www.coolcode.cn/show-41-1.html

原文如下
  1. 昨天在调试 WAP 网站时发现,在增加了 GB2312 到 UTF-8 转化以后,有些页面显示不正常了——有些页面只有一半的内容,另一半被截掉了。因为被截掉的部分包含了<p>的后半个标签</p>,因此整个页面都显示不出来,而报告错误。经过猜测、尝试,最后终于把问题集中在了 iconv 函数上。在经过高人指点以后,发现这个函数的第二个参数,除了可以指定要转化到的编码以外,还可以增加两个后缀://TRANSLIT 和 //IGNORE,其中 //TRANSLIT 会自动将不能直接转化的字符变成一个或多个近似的字符,//IGNORE 会忽略掉不能转化的字符,而默认效果是从第一个非法字符截断。但是我尝试了//TRANSLIT 和 //IGNORE 这两个后缀,效果还是不对。于是我想问题可能不是出在这里。从 GB2312 到 UTF-8 转化应该不会有不能转化的字符,因为 UTF-8 的字符集完全包含了 GB2312 中的字符,所以我想大概是前面要转化的字符集指定错了,于是我尝试着把 GB2312 改成 GBK,问题解决!虽然那两个后缀在这里没派上用场,不过也算学了一招,以后肯定会用到的。补记:改成 GBK 后,发现仍然有一封邮件的内容解析不正确。在另一位高人指点下,先换成 GB18030,问题依旧,然后改用 mb_convert_encoding 进行转换,问题解决!不知道是 mb_convert_encoding 问题,还是我的系统问题,我用 mb_convert_encoding 时不支持 GB18030 编码。另外,用 GBK 或者GB18030 作为输入编码,并在输出编码中加上 //IGNORE 后缀,用 iconv 函数也能解决那封含有错误编码的邮件内容解析不正确的问题。不过用 mb_convert_encoding 可以指定多种输入编码,它会根据内容自动识别,这个比 iconv 要好的多。  

其实,同事在生成图片文字水印的时候也遇到了这种问题,同事最初用的是GB2312字符集,结果直接报错,说是字符串的offset有问题,但仔细检查后却没有这种问题。后来才发现是直接调用的这个iconv转换出错了。
原来的转换是从gb2312往 UTF8转换,表面上确实没有什么问题,然而,现在的人特别爱装酷,受影响的那位同志,用的是繁体字,繁体字的字库大多情况是属于GBK的,所以后来换成GBK后就正常了。
估计以后再遇上用火星文的朋友,就真的只能使用andot提出的这种方法了。转换成18030,再使用ignore参数。哈哈

mbstring好象最初的版本里没有使用,如果换成这个,估计代码工作量非常大,先将就着点了

Tags: 字符转换, php, iconv, mbstring, convert

用 PHP 生成 JavaScript 字符串

闲来无事,到coolcode.cn上去闲逛。发现了一些比较旧的文章,以前也都看过,但,那时候没有开博,所以也就没有记录。如今博客也开了,coolcode.cn估计要成为我搜刮的对象了。

coolcode.cn的作者是andot,PHPRPC的作者,我06年年中(应该没记错)就使用了这个软件,同年放弃使用xajax,当然,现在我更多的使用jquery来操作ajax,但PHPRPC的功能不完全局限于ajax,我这里就不详谈了。先谈这篇文章。。。

无耻的分隔线:


原来,在从 PHP 中直接传递字符串给 JavaScript 时,直接用了 addcslashes,如果传递的是带有 utf-8 编码汉字的,就用 "\0..\037\042\134",如果纯 ascii 范围内的字符串,就用 "\0..\037\042\134\177..\377"。但是今天在写加密程序时发现,发现程序有时行,有时不行。后来发现原来是 \v \a 搞的。addcslashes 会把 \007..\015(八进制) 转义成 \a\b\t\n\v\f\r,而其中 \a 这个 IE 和 Firefox 都不认识,\v 这个 Firefox 认识,IE 不认识。所以我写了下面这个函数,用它可以就可以转化成 JavaScript/JScript 所认识的字符串了(其中 $flag 表示是否转义 ascii 码大于 127 的字符)。感谢五帝同学的帮助!

PHP代码
  1. /* @author andot & wudi */  
  2. function addjsslashes($str$flag = true)  
  3. {  
  4.     if ($flag) {  
  5.         $str = addcslashes($str"\0..\006\010..\012\014..\037\042\047\134\177..\377");   
  6.     }   
  7.     else {   
  8.         $str = addcslashes($str"\0..\006\010..\012\014..\037\042\047\134");   
  9.     }   
  10.     return str_replace(  
  11.                 array(chr(7), chr(11)),   
  12.                 array('\007''\013'),   
  13.                 $str  
  14.             );   
  15. }   

Tags: php, javascript, 进制转换