php 图像合成_使用PHP的图像乐趣–第2部分
php 图像合成
This post is a demo of what the imagefilter() PHP function can do for you.
这篇文章演示了imagefilter() PHP函数可以为您做什么。
原本的 (The Original)
使用不同的过滤器常量调用imagefilter() (imagefilter() called with different filter constants)
Filter: IMG_FILTER_BRIGHTNESSCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_BRIGHTNESS, 5); imagepng($image, 'img_filter_brightness_5.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_BRIGHTNESS要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_BRIGHTNESS , 5 ); imagepng ( $image , 'img_filter_brightness_5.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_BRIGHTNESSCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_BRIGHTNESS, 50); imagepng($image, 'img_filter_brightness_50.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_BRIGHTNESS要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_BRIGHTNESS , 50 ); imagepng ( $image , 'img_filter_brightness_50.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_BRIGHTNESSCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_BRIGHTNESS, 100); imagepng($image, 'img_filter_brightness_100.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_BRIGHTNESS要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_BRIGHTNESS , 100 ); imagepng ( $image , 'img_filter_brightness_100.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_GRAYSCALECode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GRAYSCALE); imagepng($image, 'img_filter_grayscale.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_GRAYSCALE要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GRAYSCALE ); imagepng ( $image , 'img_filter_grayscale.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_CONTRASTCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_CONTRAST, 5); imagepng($image, 'img_filter_contrast_5.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_CONTRAST代码以重现: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_CONTRAST , 5 ); imagepng ( $image , 'img_filter_contrast_5.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_CONTRASTCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_CONTRAST, -40); imagepng($image, 'img_filter_contrast_-40.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_CONTRAST代码以重现: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_CONTRAST , - 40 ); imagepng ( $image , 'img_filter_contrast_-40.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_CONTRASTCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_CONTRAST, 50); imagepng($image, 'img_filter_contrast_50.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_CONTRAST代码以重现: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_CONTRAST , 50 ); imagepng ( $image , 'img_filter_contrast_50.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_COLORIZECode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_COLORIZE, 100, 0, 0); imagepng($image, 'img_filter_colorize_100_0_0.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_COLORIZE要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_COLORIZE , 100 , 0 , 0 ); imagepng ( $image , 'img_filter_colorize_100_0_0.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_COLORIZECode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_COLORIZE, 0, 100, 0); imagepng($image, 'img_filter_colorize_0_100_0.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_COLORIZE要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_COLORIZE , 0 , 100 , 0 ); imagepng ( $image , 'img_filter_colorize_0_100_0.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_COLORIZECode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_COLORIZE, 0, 0, 100); imagepng($image, 'img_filter_colorize_0_0_100.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_COLORIZE要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_COLORIZE , 0 , 0 , 100 ); imagepng ( $image , 'img_filter_colorize_0_0_100.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_COLORIZECode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_COLORIZE, 100, 100, -100); imagepng($image, 'img_filter_colorize_100_100_-100.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_COLORIZE要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_COLORIZE , 100 , 100 , - 100 ); imagepng ( $image , 'img_filter_colorize_100_100_-100.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_COLORIZECode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_COLORIZE, 50, -50, 50); imagepng($image, 'img_filter_colorize_50_-50_50.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_COLORIZE要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_COLORIZE , 50 , - 50 , 50 ); imagepng ( $image , 'img_filter_colorize_50_-50_50.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_EDGEDETECTCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_EDGEDETECT); imagepng($image, 'img_filter_edgedetect.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_EDGEDETECT代码以重现: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_EDGEDETECT ); imagepng ( $image , 'img_filter_edgedetect.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_EMBOSSCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_EMBOSS); imagepng($image, 'img_filter_emboss.png'); imagedestroy($image); ?>
过滤器:要重现的IMG_FILTER_EMBOSSCode: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_EMBOSS ); imagepng ( $image , 'img_filter_emboss.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_GAUSSIAN_BLURCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR); imagepng($image, 'img_filter_gaussian_blur.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_GAUSSIAN_BLUR要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GAUSSIAN_BLUR ); imagepng ( $image , 'img_filter_gaussian_blur.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_SELECTIVE_BLURCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_SELECTIVE_BLUR); imagepng($image, 'img_filter_selective_blur.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_SELECTIVE_BLUR要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_SELECTIVE_BLUR ); imagepng ( $image , 'img_filter_selective_blur.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_MEAN_REMOVALCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_MEAN_REMOVAL); imagepng($image, 'img_filter_mean_removal.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_MEAN_REMOVAL要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_MEAN_REMOVAL ); imagepng ( $image , 'img_filter_mean_removal.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_SMOOTHCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_SMOOTH, 5); imagepng($image, 'img_filter_smooth_5.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_SMOOTH要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_SMOOTH , 5 ); imagepng ( $image , 'img_filter_smooth_5.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_SMOOTHCode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_SMOOTH, 50); imagepng($image, 'img_filter_smooth_50.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_SMOOTH要重现的代码: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_SMOOTH , 50 ); imagepng ( $image , 'img_filter_smooth_50.png' ); imagedestroy ( $image ); ?>
Filter: IMG_FILTER_NEGATECode to reproduce: <?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_NEGATE); imagepng($image, 'img_filter_negate.png'); imagedestroy($image); ?>
过滤器:IMG_FILTER_NEGATE代码以重现: <?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_NEGATE ); imagepng ( $image , 'img_filter_negate.png' ); imagedestroy ( $image ); ?>
棕褐色的懒惰方式 (A lazy way to do sepia)
In order to do sepia, first you do grayscale, then colorize. Here are some experiments:
为了进行棕褐色处理,首先要进行灰度处理,然后进行着色。 以下是一些实验:
<?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GRAYSCALE); imagefilter($image, IMG_FILTER_COLORIZE, 100, 50, 0); imagepng($image, 'sepia_100_50_0.png'); imagedestroy($image); ?>
<?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GRAYSCALE ); imagefilter ( $image , IMG_FILTER_COLORIZE , 100 , 50 , 0 ); imagepng ( $image , 'sepia_100_50_0.png' ); imagedestroy ( $image ); ?>
<?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GRAYSCALE); imagefilter($image, IMG_FILTER_COLORIZE, 100, 70, 50); imagepng($image, 'sepia_100_70_50.png'); imagedestroy($image); ?>
<?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GRAYSCALE ); imagefilter ( $image , IMG_FILTER_COLORIZE , 100 , 70 , 50 ); imagepng ( $image , 'sepia_100_70_50.png' ); imagedestroy ( $image ); ?>
<?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GRAYSCALE); imagefilter($image, IMG_FILTER_COLORIZE, 90, 60, 30); imagepng($image, 'sepia_90_60_30.png'); imagedestroy($image); ?>
<?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GRAYSCALE ); imagefilter ( $image , IMG_FILTER_COLORIZE , 90 , 60 , 30 ); imagepng ( $image , 'sepia_90_60_30.png' ); imagedestroy ( $image ); ?>
<?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GRAYSCALE); imagefilter($image, IMG_FILTER_COLORIZE, 60, 60, 0); imagepng($image, 'sepia_60_60_0.png'); imagedestroy($image); ?>
<?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GRAYSCALE ); imagefilter ( $image , IMG_FILTER_COLORIZE , 60 , 60 , 0 ); imagepng ( $image , 'sepia_60_60_0.png' ); imagedestroy ( $image ); ?>
<?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GRAYSCALE); imagefilter($image, IMG_FILTER_COLORIZE, 90, 90, 0); imagepng($image, 'sepia_90_90_0.png'); imagedestroy($image); ?>
<?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GRAYSCALE ); imagefilter ( $image , IMG_FILTER_COLORIZE , 90 , 90 , 0 ); imagepng ( $image , 'sepia_90_90_0.png' ); imagedestroy ( $image ); ?>
<?php $image = imagecreatefrompng('nathalie.png'); imagefilter($image, IMG_FILTER_GRAYSCALE); imagefilter($image, IMG_FILTER_COLORIZE, 45, 45, 0); imagepng($image, 'sepia_45_45_0.png'); imagedestroy($image); ?>
<?php $image = imagecreatefrompng ( 'nathalie.png' ); imagefilter ( $image , IMG_FILTER_GRAYSCALE ); imagefilter ( $image , IMG_FILTER_COLORIZE , 45 , 45 , 0 ); imagepng ( $image , 'sepia_45_45_0.png' ); imagedestroy ( $image ); ?>
You can read about the right way to do sepia in Wikipedia, but I'd say that the fakes above look pretty good too. You can try with different values for R, G and B, but hear this - the thing about sepia is that it's brownish-yellow. Brown is something that has more red, little blue and the green exactly in between the red and the blue. So brown examples would be (200, 100, 0) or (150, 100, 50). Yellow on the other hand is equal red and green and no blue, like (255, 255, 0). So if you want more brownish sepia, use the first pattern when calling the colorize filter.
您可以在Wikipedia中阅读有关进行棕褐色处理的正确方法,但是我想说上面的假冒品也相当不错。 您可以尝试使用不同的R,G和B值,但请听一下-棕褐色的颜色是棕黄色。 棕色是在红色和蓝色之间恰好具有更多的红色,蓝色和绿色的东西。 因此,褐色示例为(200,100,0)或(150,100,50)。 另一方面,黄色等于红色和绿色,没有蓝色,例如(255,255,0)。 因此,如果您想要更棕褐色的棕褐色,请在调用colorize滤镜时使用第一个图案。
关于第一部分 (About part one)
Part one of the image fun is here, it contains code that more or less does the same things, but pixel by pixel, which is very slow, but also works in PHP4. At the time of writing part one, imagefilter() funtion was probaly only in cvs, not part of the official PHP. imagefilter() is PHP5-only.
有趣的图像的第一部分在这里 ,它包含的代码或多或少地执行了相同的操作,但是逐像素,这非常慢,而且可以在PHP4中使用。 在编写第一部分时,imagefilter()函数仅在cvs中有效,而在正式PHP中则没有。 imagefilter()仅限于PHP5。
Tell your friends about this post on Facebook and Twitter
在Facebook和Twitter上告诉您的朋友有关此帖子的信息
php 图像合成