开发者 | fab1en |
---|---|
更新时间 | 2013年10月28日 23:01 |
PHP版本: | 3.0.1 及以上 |
WordPress版本: | 3.7 |
版权: | GPLv3 or later |
版权网址: | 版权信息 |
functions.php
, instead of using WP add_image_size function, use grayscale_add_image_size('custom_size', xxx, yyy, $crop, $grayscale)
(with $crop
set to true
if you want to crop the image, and $grayscale
set to true
if you want a grayscale version of the image). Then, you can use the_post_thumbnail or any thumbnail function to get your grayscale image :
the_post_thumbnail('custom_size-gray')
A gamma correction is applied automatically to make the black & white pictures look good. From version 1.2, You can tune this gamma correction with the grayscale_gamma_correction
filter. Your filter would have to return a float number that will be use as the outputgamma
parameter of the imagegammacorrect function.
Known bugs
No, a colored thumbnail at the specified size is already created. You can display it with the_post_thumbnail('custom_size')
whereas the black and white one will use the_post_thumbnail('custom_size-gray')
.