Submitted by gouki on 2008, August 4, 7:21 PM
原文如下:附本人翻译(翻译水平其差,可以忽略直接看英文)
原文网址:http://valokuva.org/?p=92
- 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.
-
- 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 :)
-
- 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代码
- <?php
-
- /* 定义缩略图的长宽*/
- $width = 100;
- $height = 100;
-
- /*创建一个对象,同时读回源图*/
- $im = new Imagick( "test.png" );
-
-
- /*按照比例进行缩放*/
- $im->thumbnailImage( $width, $height, true );
-
- $canvas = new Imagick();
- $canvas->newImage( $width, $height, 'pink', 'png' );
-
- $geometry = $im->getImageGeometry();
-
- $x = ( $width - $geometry['width'] ) / 2;
- $y = ( $height - $geometry['height'] ) / 2;
-
- $canvas->compositeImage( $im, imagick::COMPOSITE_OVER, $x, $y );
-
- header( "Content-Type: image/png" );
- echo $canvas;
- ?>
膘叔,上图片
源图:
缩图:
Tags: php, imagemagick, magicwand, thumbnail
PHP | 评论:1
| 阅读:24307
Submitted by gouki on 2008, August 4, 4:00 PM
啥也不说了。自己看列表吧。。原来,更新了这么多啊。。。。。。现在还是alpha,等到了stable,那我应该不应该更新呢》》》
更新列表(请看第44行哦)
- PHP NEWS
- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- ?? ??? 200?, PHP 5.3.0 Alpha 2
- - Removed shebang line check from CGI sapi (it is checked by scanner) (Dmitry)
-
- - Fixed bug #45696 (Not all DateTime methods allow method chaining). (Derick)
- - Fixed bug #45545 (DateInterval has a limitation of 4 chars for ISO
- durations). (Derick)
- - Fixed bug #45406 (session.serialize_handler declared by shared extension
- fails). (Kalle, oleg dot grenrus at dynamoid dot com)
- - Fixed bug #44100 (Inconsistent handling of static array declarations with
- duplicate keys). (Dmitry)
- - Fixed bug #43008 (php://filter uris ignore url encoded filternames and can't
- handle slashes). (Arnaud)
-
- 01 Aug 2008, PHP 5.3.0 Alpha 1
- - Upgraded bundled PCRE to version 7.7. (Nuno)
- - Upgraded bundled PDO sqlite to version 3.5.9. (Scott)
-
- - Moved extensions to PECL (Pierre):
- . ext/fdf
- . ext/ncurses
- . ext/sybase (not maintained anymore, sybase_ct has to be used instead)
-
- - Removed the experimental RPL (master/slave) functions from mysqli. (Andrey)
- - Removed zend.ze1_compatibility_mode. (Dmitry)
- - Deprecated ticks support. (Felipe)
-
- - Changed PCRE, Reflection and SPL extensions to be always enabled. (Marcus)
- - Changed md5() to use improved implementation. (Solar Designer, Dmitry)
- - Changed HTTP stream wrapper to accept any code between and including
- 200 to 399 as successful. (Mike, Noah Fontes)
-
- - Improved PHP syntax and semantics:
- . Added lambda functions and closures. (Christian Seiler, Dmitry)
- . Added "jump label" operator (limited "goto"). (Dmitry, Sara)
- . Added NOWDOC syntax. (Gwynne Raskind, Stas, Dmitry)
- . Added HEREDOC syntax with double quotes. (Lars Strojny, Felipe)
- . Added support for using static HEREDOCs to initialize static variables and
- class members or constants. (Matt)
- . Improved syntax highlighting and consistency for variables in double-quoted
- strings and literal text in HEREDOCs and backticks. (Matt)
- . Added "?:" operator. (Marcus)
- . Added support for namespaces. (Dmitry, Stas, Gregory)
- . Added support for Late Static Binding. (Dmitry, Etienne Kneuss)
- . Added support for __callStatic() magic method. (Sara)
- . Added forward_static_call(_array) to complete LSB. (Mike Lively)
- . Added support for dynamic access of static members using $foo::myFunc().
- (Etienne Kneuss)
- . Improved checks for callbacks. (Marcus)
- . Added __DIR__ constant. (Lars Strojny)
- . Added PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION,
- PHP_EXTRA_VERSION, PHP_VERSION_ID, PHP_ZTS and PHP_DEBUG constants.
- (Pierre)
- . Added new error modes E_USER_DEPRECATED and E_DEPRECATED.
- E_DEPRECATED is used to inform about stuff being scheduled for removal
- in future PHP versions. (Lars Strojny, Felipe, Marcus)
- . Added "request_order" INI variable to control specifically $_REQUEST
- behavior. (Stas)
- . Added support for exception linking. (Marcus)
- . Added ability to handle exceptions in destructors. (Marcus)
-
- - Improved PHP runtime speed and memory usage:
- . Substitute persistent constants by their values at compile time. (Matt)
- . Optimized ZEND_SIGNED_MULTIPLY_LONG(). (Matt)
- . Removed direct executor recursion. (Dmitry)
- . Use fastcall calling convention in executor on x86. (Dmitry)
- . Use IS_CV for direct access to $this variable. (Dmitry)
- . Use ZEND_FREE() opcode instead of ZEND_SWITCH_FREE(IS_TMP_VAR). (Dmitry)
- . Lazy EG(active_symbol_table) initialization. (Dmitry)
- . Optimized ZEND_RETURN opcode to not allocate and copy return value if it is
- not used. (Dmitry)
- . Replaced all flex based scanners with re2c based scanners.
- (Marcus, Nuno, Scott)
- . Added garbage collector. (David Wang, Dmitry).
- . Improved PHP binary size and startup speed with GCC4 visibility control.
- (Nuno)
- . Improved engine stack implementation for better performance and stability.
- (Dmitry)
- . Improved memory usage by moving constants to read only memory.
- (Dmitry, Pierre)
- . Changed exception handling. Now each op_array doesn't contain
- ZEND_HANDLE_EXCEPTION opcode in the end. (Dmitry)
- . Optimized require_once() and include_once() by eliminating fopen(3) on
- second usage. (Dmitry)
- . Optimized ZEND_FETCH_CLASS + ZEND_ADD_INTERFACE into single
- ZEND_ADD_INTERFACE opcode. (Dmitry)
- . Optimized string searching for a single character.
- (Michal Dziemianko, Scott)
- . Optimized interpolated strings to use one less opcode. (Matt)
-
- - Improved php.ini handling: (Jani)
- . Added ".htaccess" style user-defined php.ini files support for CGI/FastCGI.
- . Added support for special [PATH=/opt/httpd/www.example.com/] and
- [HOST=www.example.com] sections. Directives set in these sections can
- not be overridden by user-defined ini-files or during runtime.
- . Added better error reporting for php.ini syntax errors.
- . Allowed using full path to load modules using "extension" directive.
- . Allowed "ini-variables" to be used almost everywhere ini php.ini files.
- . Allowed using alphanumeric/variable indexes in "array" ini options.
- . Added 3rd optional parameter to parse_ini_file() to specify the scanning
- mode of INI_SCANNER_NORMAL or INI_SCANNER_RAW. In raw mode option values
- and section values are treated as-is.
- . Fixed get_cfg_var() to be able to return "array" ini options.
- . Added optional parameter to ini_get_all() to only retrieve the current
- value. (Hannes)
-
- - Improved and cleaned CGI code:
- . FastCGI is now always enabled and can not be disabled.
- See sapi/cgi/CHANGES for more details. (Dmitry)
- . Added CGI SAPI -T option which can be used to measure execution
- time of script repeated several times. (Dmitry)
-
- - Improved streams:
- . Fixed confusing error message on failure when no errors are logged. (Greg)
- . Added stream_supports_lock() function. (Benjamin Schulz)
- . Added "ignore_errors" option to http fopen wrapper. (David Zulke, Sara)
- . Added context parameter for copy() function. (Sara)
- . Added "glob://" stream wrapper. (Marcus)
- . Added "params" as optional parameter for stream_context_create(). (Sara)
- . Added ability to use stream wrappers in include_path. (Gregory, Dmitry)
-
- - Improved hash extension:
- . Changed mhash to be a wrapper layer around the hash extension. (Scott)
- . Added hash_copy() function. (Tony)
- . Added sha224 hash algorithm to the hash extension. (Scott)
-
- - Improved mbstring extension:
- . Added "mbstring.http_output_conv_mimetypes" INI directive that allows
- common non-text types such as "application/xhtml+xml" to be converted
- by mb_output_handler(). (Moriyoshi)
-
- - Improved OCI8 extension (Chris Jones/Oracle Corp.):
- . Added Database Resident Connection Pooling (DRCP) and Fast
- Application Notification (FAN) support.
- . Added support for Oracle External Authentication (not supported
- on Windows).
- . Improve persistent connection handling of restarted DBs.
- . Added SQLT_AFC (aka CHAR datatype) support to oci_bind_by_name.
- . Fixed bug #41069 (Seg fault with query over DB link).
- . Fixed define of SQLT_BDOUBLE and SQLT_BFLOAT constants with Oracle
- 10g ORACLE_HOME builds.
- . Changed default value of oci8.default_prefetch from 10 to 100.
- . Fixed PECL bug #12431 (OCI8 ping functionality is broken).
- . Allow building (e.g from PECL) the PHP 5.3-based OCI8 code with
- PHP 4.3.9 onwards.
-
- - Improved OpenSSL extension: (Dmitry)
- . Added support for OpenSSL digest and cipher functions.
- . Added access to internal values of DSA, RSA and DH keys.
-
- - Improved pcntl extension: (Arnaud)
- . Added pcntl_signal_dispatch().
- . Added pcntl_sigprocmask().
- . Added pcntl_sigwaitinfo().
- . Added pcntl_sigtimedwait().
-
- - Improved SOAP extension:
- . Added support for element names in context of XMLShema's <any>. (Dmitry)
- . Added ability to use Traversable objects instead of plain arrays.
- (Joshua Reese, Dmitry)
- . Fixed possible crash bug caused by an uninitialized value. (Zdash Urf)
-
- - Improved SPL extension:
- . Added SPL to list of standard extensions that cannot be disabled. (Marcus)
- . Added ability to store associative information with objects in
- SplObjectStorage. (Marcus)
- . Added ArrayAccess support to SplObjectStorage. (Marcus)
- . Added SplDoublyLinkedList, SplStack, SplQueue classes. (Etienne)
- . Added FilesystemIterator. (Marcus)
- . Added GlobIterator. (Marcus)
- . Added SplHeap, SplMinHeap, SplMaxHeap, SplPriorityQueue classes. (Etienne)
- . Added new parameter $prepend to spl_autoload_register(). (Etienne)
- . Added FixedArray. (Etienne, Tony)
- . Added delaying exceptions in SPL's autoload mechanism. (Marcus)
- . Added RecursiveTreeIterator. (Arnaud, Marcus)
- . Added MultipleIterator. (Arnaud, Marcus, Johannes)
-
- - Improved Zend Engine:
- . Added "compact" handler for Zend MM storage. (Dmitry)
- . Added "+" and "*" specifiers to zend_parse_parameters(). (Andrei)
- . Added concept of "delayed early binding" that allows opcode caches to
- perform class declaration (early and/or run-time binding) in exactly
- the same order as vanilla PHP. (Dmitry)
-
- - Improved crypt() function: (Pierre)
- . Added Blowfish and extended DES support. (Using Blowfish implementation
- from Solar Designer).
- . Made crypt features portable by providing our own implementations
- for crypt_r and the algorithms which are used when OS does not provide
- them. PHP implementations are always used for Windows builds.
-
- - Added new extensions:
- . Added fileinfo extension as replacement for mime_magic extension. (Derick)
- . Added intl extension for Internationalization. (Ed B., Vladimir I.,
- Dmitry L., Stanislav M., Vadim S., Kirti V.)
- . Added mysqlnd extension as replacement for libmysql for ext/mysql, mysqli
- and PDO_mysql. (Andrey, Johannes, Ulf)
- . Added phar extension for handling PHP Archives. (Greg, Marcus, Steph)
- . Added SQLite3 extension. (Scott)
-
- - Added new date/time functionality: (Derick)
- . date_parse_from_format(): Parse date/time strings according to a format.
- . date_create_from_format()/DateTime::createFromFormat(): Create a date/time
- object by parsing a date/time string according to a given format.
- . date_get_last_errors()/DateTime::getLastErrors(): Return a list of warnings
- and errors that were found while parsing a date/time string through:
- . strtotime() / new DateTime
- . date_create_from_format() / DateTime::createFromFormat()
- . date_parse_from_format().
- . support for abbreviation and offset based timezone specifiers for
- DateTime::getOffset() and DateTime::getName().
- . support for selectively listing timezone identifiers by continent or
- country code through timezone_identifiers_list() /
- DateTimezone::listIdentifiers().
- . timezone_location_get() / DateTimezone::getLocation() for retrieving
- location information from timezones.
- . date_timestamp_set() / DateTime::setTimestamp() to set a Unix timestamp
- without invoking the date parser. (Scott, Derick)
- . date_timestamp_get() / DateTime::getTimestamp() to retrieve the Unix
- timestamp belonging to a date object.
- . two optional parameters to timezone_transitions_get() /
- DateTimeZone::getTranstions() to limit the range of transitions being
- returned.
- . support for "first/last day of <month>" style texts.
- . support for date/time strings returned by MS SQL.
- . support for serialization and unserialization of DateTime objects.
- . support for diffing date/times through date_diff() / DateTime::diff().
- . support for adding/subtracting weekdays with strtotime() and
- DateTime::modify().
- . DateInterval class to represent the difference between two date/times.
- . support for parsing ISO intervals for use with DateInterval.
- . date_add() / DateTime::add(), date_sub() / DateTime::sub() for applying an
- interval to an existing date/time.
- . proper support for "this week", "previous week"/"last week" and "next week"
- phrases so that they actually mean the week and not a seven day period
- around the current day.
- . support for "<xth> <weekday of" and "last <weekday> of" phrases to be used
- with months - like in "last saturday of februari 2008".
- . DatePeriod class which supports iterating over a DateTime object applying
- DateInterval on each iteration, up to an end date or limited by maximum
- number of occurences.
-
- - Added array_replace() and array_replace_recursive() functions. (Matt)
- - Added ReflectionProperty::setAccessible() method that allows non-public
- property's values to be read through ::getValue(). (Derick)
- - Added msg_queue_exists() function to sysvmsg extension. (Benjamin Schulz)
- - Added Firebird specific attributes that can be set via PDO::setAttribute()
- to control formatting of date/timestamp columns: PDO::FB_ATTR_DATE_FORMAT,
- PDO::FB_ATTR_TIME_FORMAT and PDO::FB_ATTR_TIMESTAMP_FORMAT. (Lars W)
- - Added gmp_testbit() function. (Stas)
- - Added icon format support to getimagesize(). (Scott)
- - Added LDAP_OPT_NETWORK_TIMEOUT option for ldap_set_option() to allow
- setting network timeout (FR #42837). (Jani)
- - Added optional escape character parameter to fgetcsv(). (David Soria Parra)
- - Added an optional parameter to strstr() and stristr() for retrieval of either
- the part of haystack before or after first occurrence of needle.
- (Johannes, Felipe)
- - Added xsl->setProfiling() for profiling stylesheets. (Christian)
- - Added long-option feature to getopt() and made getopt() available also on
- win32 systems by adding a common getopt implementation into core.
- (David Soria Parra, Jani)
- - Added support for optional values, and = as separator, in getopt(). (Hannes)
- - Added lcfirst() function. (David C)
- - Added PREG_BAD_UTF8_OFFSET_ERROR constant. (Nuno)
- - Added native support for asinh(), acosh(), atanh(), log1p() and expm1().
- (Kalle)
- - Added inet_pton() and inet_ntop() also for Windows platforms. (Kalle)
- - Added mcrypt_create_iv() also for Windows platforms. (Pierre)
-
- - Fixed html_entity_decode() incorrectly converting numeric html entities
- to different characters with cp1251 and cp866. (Scott)
- - Fixed an issue in date() where a : was printed for the O modifier after a P
- modifier was used. (Derick)
- - Fixed exec() on Windows to not eat the first and last double quotes. (Scott)
-
- - Fixed PECL bug #12794 (PDOStatement->nextRowset() doesn�t work). (Johannes)
- - Fixed PECL bug #12401 (Add support for ATTR_FETCH_TABLE_NAMES). (Johannes)
-
- - Fixed bug #45622 (isset($arrayObject->p) misbehaves with ArrayObject::
- ARRAY_AS_PROPS set). (robin_fernandes at uk dot ibm dot com, Arnaud)
- - Fixed bug #45614 (ArrayIterator::current(), ::key() can show 1st private
- prop of wrapped object). (robin_fernandes at uk dot ibm dot com, Arnaud)
- - Fixed bug #45571 (ReflectionClass::export() shows superclasses' private
- static methods). (robin_fernandes at uk dot ibm dot com)
- - Fixed bug #45540 (stream_context_create creates bad http request). (Arnaud)
- - Fixed bug #45430 (windows implementation of crypt is not thread safe).
- (Pierre)
- - Fixed bug #45345 (SPLFileInfo::getPathInfo() returning dir info instead of
- file info). (Etienne)
- - Fixed bug #45179 (--with-mysql-sock fails to compile & work). (Andrey)
- - Fixed bug #45038 (Crash when using DateTimeZone object returned by
- Date::getTimezone). (Joe Orton, Derick)
- - Fixed bug #44769 (declaring private magic methods should throw error).
- (Felipe)
- - Fixed bug #44913 (Segfault when using return in combination with nested loops
- and continue 2). (Dmitry)
- - Fixed bug #44899 (__isset usage changes behavior of empty()). (Etienne)
- - Fixed bug #44897 (failed to prepare statement). (Andrey)
- - Fixed bug #44849 (imagecolorclosesthwb() is not available on Windows).
- (Kalle)
- - Fixed bug #44805 (rename() function is not portable to Windows). (Pierre)
- - Fixed bug #44779 (filter returns NULL in CLI when it shouldn't). (Arnaud)
- - Fixed bug #44742 (timezone_offset_get() causes segmentation faults). (Derick)
- - Fixed bug #44660 (Indexed and reference assignment to propery of non-object
- don't trigger warning). (Dmitry)
- - Fixed bug #44648 (Attribute names not checked for wellformedness). (Rob)
- - Fixed bug #44414 (Incomplete reporting about abstract methods). (Dmitry)
- - Fixed bug #44390 (mysqli_bind_param/bind_result and Object member variables).
- (Andrey)
- - Fixed bug #44352 (mysqli_connect_error() false negative for host errors).
- (Andrey)
- - Fixed bug #44336 (Improve pcre UTF-8 string matching performance).
- (frode at coretrek dot com, Nuno)
- - Fixed bug #44301 (Segfault when an exception is thrown on persistent
- connections). (Martin Jansen)
- - Fixed bug #44257 (timelib_tz_lookup_table must use float for gmtoffset).
- (Derick, iuri dot fiedoruk at hp dot com).
- - Fixed bug #44214 (Crash using preg_replace_callback() and global variable).
- (Nuno, Scott)
- - Fixed bug #44034 (FILE_IGNORE_NEW_LINES in file() does not work as expected
- when lines end in \r\n). (Ilia)
- - Fixed bug #43960 (strtotime() returns timestamp in the future when given a
- bogus string). (Derick)
- - Fixed bug #43832 (mysqli_get_charset() doesn't expose charset comment).
- (Andrey)
- - Fixed bug #43808 (date_create never fails (even when it should)). (Derick)
- - Fixed bug #43527 (DateTime created from a timestamp reports environment
- timezone). (Derick)
- - Fixed bug #43452 (strings containing a weekday, or a number plus weekday
- misbehaved if the current day-of-week was same as the one in the phrase).
- (Derick)
- - Fixed bug #43426 (crash on nested call_user_func() calls). (Dmitry)
- - Fixed bug #43323 (Wrong count abstract methods). (Felipe, Dmitry)
- - Fixed bug #43261 (Use ^ as the escape with escapeshellcmd() on Windows).
- (Scott)
- - Fixed bug #43075 (Support 2007-11-01T24:00:00+00:00). (Derick)
- - Fixed bug #43003 (Invalid timezone reported for DateTime objects constructed
- using a timestamp). (Derick)
- - Fixed bug #43143 (Warning about empty IV with MCRYPT_MODE_ECB). (Derick)
- - Fixed bug #43136 (possible crash on script execution timeout.
- The EG(function_state_ptr) is completely removed,
- EG(current_execute_data)->function_state must be used instead). (Dmitry)
- - Fixed bug #42952 (soap cache file is created with insecure permissions).
- (Dmitry)
- - Fixed bug #42868 (Floats cast to integer produce unpredictable results).
- (Zoe Slattery)
- - Fixed bug #42848 (Status: header incorrect under FastCGI). (Dmitry)
- - Fixed bug #42773 (WSDL error causes HTTP 500 Response). (Dmitry)
- - Fixed bug #42737 (preg_split('//u') triggers a E_NOTICE with newlines).
- (Nuno)
- - Fixed bug #42736 (xmlrpc_server_call_method() crashes). (Tony)
- - Fixed bug #42663 (gzinflate() try to allocate all memory with truncated
- data). (Arnaud)
- - Fixed bug #42657 (ini_get() returns incorrect value when default is NULL).
- (Jani, Scott)
- - Fixed bug #42637 (SoapFault : Only http and https are allowed). (Bill Moran)
- - Fixed bug #42548 (mysqli PROCEDURE calls can't return result sets). (Hartmut)
- - Fixed bug #42509 (gmp leaks memory when gmp_init() not used). (Stas)
- - Fixed bug #42499 (PDO_MYSQL: multi-statement execution via PDO::exec() makes
- connection unusable). (Johannes)
- - Fixed bug #42443 (PDO SQLite driver binds integers and booleans as strings).
- (Scott)
- - Fixed bug #42284 (duplicate of #39700). (Lars W)
- - Fixed bug #42203 (Clear SQLite result sets before closing database). (Scott)
- - Fixed bug #42190 (Constructing DateTime with TimeZone Indicator invalidates
- DateTimeZone). (Derick)
- - Fixed bug #42069 (parse_ini_file() allows using some non-alpha numeric
- characters). (Jani)
- - Fixed bug #41997 (pdo_mysql: stored procedure call returning single rowset
- blocks future queries). (Johannes)
- - Fixed bug #41996 (Problem accessing Oracle ROWID). (Martin Jansen)
- - Fixed bug #41599 (setTime() fails after modify() is used). (Derick)
- - Fixed bug #41522 (PDO firebird driver returns null if it fails to connect).
- (Lars W)
- - Fixed bug #41135 (PDO SQLite driver binds blobs as strings,
- use sqlite3_bind_blob() to stop errors with null bytes). (Scott)
- - Fixed bug #39822 (new PDO() doesn't work with firebird). (Lars W)
- - Fixed bug #39700 (NUMERIC error when result precision are 7,8 or 12-14 ).
- (Lars W)
- - Fixed bug #39457 (Multiple invoked OO connections never close). (Andrey)
- - Fixed bug #39397 (invalid statement handle in Unknown on line 0). (Lars W)
- - Fixed bug #39346 (Unsetting a static variable inside a destructor causes
- segfault later on). (Dmitry)
- - Fixed bug #39127 (Old-style constructor fallbacks produce strange results).
- (Tony)
- - Fixed bug #39056 (Interbase NUMERIC data type error). (Lars W)
- - Fixed bug #39018 (Error control operator '@' fails to suppress "Uninitialized
- string offset"). (Felipe)
- - Fixed bug #38468 (Unexpected creation of cycle). (Dmitry)
- - Fixed bug #37964 (Reflection shows private methods of parent class).
- (Felipe, Marcus)
- - Fixed bug #37911 (preg_replace_callback() ignores named groups). (Nuno)
- - Fixed bug #37076 (SimpleXML ignores .=). (Felipe, Marcus)
- - Fixed bug #36128 (Interbase PDO - timestamp columns return NULL). (Lars W)
- - Fixed bug #35386 (firebird: first row is null). (Lars W)
- - Fixed bug #35163 (Array elements can lose references). (Dmitry)
- - Fixed bug #32330 (session_destroy, "Failed to initialize storage module",
- custom session handler). (Gwynne)
- - Fixed bug #32143 (ibase_query() causing IBserver 7 crash with NULL param as
- link-id). (Lars W)
- - Fixed bug #30907 (ibase_query() crashes (same bug as #32143). (Lars W)
- - Fixed bug #30690 (Resource handle from ibase_execute becomes invalid after
- return). (Lars W)
- - Fixed bug #29044 (compact() does not have infinite recursion protection).
- (Tony)
- - Fixed bug #27372 (parse error loading browscap.ini at apache startup).
- (Jani)
Tags: php, upgrade, namespace
PHP | 评论:1
| 阅读:26644
Submitted by gouki on 2008, August 2, 8:23 PM
作者:andot,来自:www.coolcode.cn,出处:http://www.coolcode.cn/show-41-1.html
原文如下
- 昨天在调试 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 | 评论:0
| 阅读:24136
Submitted by gouki on 2008, August 2, 8:14 PM
目的:
对目前已有的 Web 应用系统,和将来待开发的 Web 应用系统进行集成,实现单点登录。
要求:
- 对已有的 Web 应用系统不作大规模改造。
- 不限制待开发的 Web 应用系统的开发工具。
- 不增加待开发系统的开发难度。
分析:
- 目前,已有的系统都各自维护自己的一套用户库,每个系统中的用户数、用户名、密码几乎都各不相同。要将已有的用户库进行统一是不现实的。因此,我们可以通过将单点登录系统中的用户与其它个系统中的用户建立映射,来实现用一个帐号来管理多个系统的目的。
- 已 有的 Web 应用系统、以及待开发的 Web 应用系统,可能不在同一个域下,虽然会话本身是保存在服务器端,但是会话 id 是需要 cookie 来传递的,而 cookie 不允许跨域访问,而且考虑到各个系统的开发工具也各不相同,即使在同一个域下,不同的开发工具所开发的应用程序之间也很难共享会话,因此要用共享会话的方 式来实现单点登录也不现实。因此我们通过在客户端浏览器、单点登录系统和 Web 应用系统之间传递临时会话,并让 Web 应用系统直接到单点登录系统中获取认证信息来实现单点登录。为保证不同开发工具都能够到单点登录系统获取认证信息,我们采用 xml-rpc 在 Web 应用系统和单点登录系统之间进行通讯。
实现:
单点登录系统中设置 4 个表:
- 单点登录系统用户表,包含 user_id,name,password 3 个字段。
- Web 应用系统表,包含 app_id,name(Web 应用系统名称),checkurl(Web 应用系统中用来验证用户登录的程序地址) 3 个字段。
- 单点登录系统用户到各个 Web 应用系统的用户映射表,包含id,user_id,app_id,name,password 5 个字段。
- 临时会话表,包含 hash(临时会话的 hash 编号),id(对应单点登录系统用户到各个 Web 应用系统的用户映射表中的 id 字段) 2个字段。
用户登录单点登录系统时,通过单点登录系统用户表中的字段来验证用户身份。登录以后,用户可以设置各个系统到该系统用户的映射关系。设置好以后,当通过该 系统进入其他某个 Web 应用系统时,该系统会为该用户和该系统生成一个临时会话编号(hash),并转到 Web 应用系统中的登录检测页面,登录检测页面通过获取到的临时会话编号,来调用单点登录系统的获取用户名和密码的 xml-rpc API,如果用户名密码如果正确,则转到正常登录后的页面,如果不正确,则转到登录错误的页面。这里,xml-rpc API 在返回用户名和密码后,将删除单点登录系统数据库中相应的临时会话,这样不但用户名、密码都是在服务器之间进行传递的,并且临时会话存在的时间也是尽可能 的短,因此只要保证服务器之间的对话不能被监听,即可保证安全性。 已有系统需要增加一个用于单点登录系统的登录验证页面,该页面工作过程大致如下:
- 获取 客户端 hash 值
- 通过 hash 值得到用户名和密码(xml-rpc 调用)
- 通过用户名和密码进行身份验证
- 返回身份验证后的页面
原作者:andot,来源coolcode.cn,原文:http://www.coolcode.cn/show-89-1.html
Tags: 登录, 设计, 通行证
PHP | 评论:0
| 阅读:24123
Submitted by gouki on 2008, August 2, 8:12 PM
闲来无事,到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代码
-
- function addjsslashes($str, $flag = true)
- {
- if ($flag) {
- $str = addcslashes($str, "\0..\006\010..\012\014..\037\042\047\134\177..\377");
- }
- else {
- $str = addcslashes($str, "\0..\006\010..\012\014..\037\042\047\134");
- }
- return str_replace(
- array(chr(7), chr(11)),
- array('\007', '\013'),
- $str
- );
- }
Tags: php, javascript, 进制转换
PHP | 评论:0
| 阅读:22674