imagesetpixel() - gd函数(图像处理)
imagesetpixel()
(PHP 4, PHP 5, PHP 7)
画一个单一像素
说明
imagesetpixel(resource $image,int $x,int $y,int $color): boolimagesetpixel()在$image图像中用$color颜色在$x,$y坐标(图像左上角为 0,0)上画一个点。
参见imagecreatetruecolor()和imagecolorallocate()。
This code does generate a RGB-cube (with or without borders). Because its only rendering the visible pixels its clearly fast (approx 1 up to 2 seconds). With changing the $order-variable you can see the cube from different perspectives. Entering double or tribble values (like rrg or ggg) will give you other specs of single channels. Send any sugestions to my email.
making images with white (or close to white) background transprent
It IS posible to "delete" pixels from an image in PHP natively - the key-function is imageAlphaBlending:
Given an image $src and mask $mask, this applies the mask over the image, using different levels of transparency properly. If your mask is reversed, change 127 - $mask_pix_color['alpha'] with just $mask_pix_color['alpha']
another gradient example that can do horizontal or vertical gradients
Just a simple implementation of the Bresenham algorythm (educational purpose....) You can find more about this and many other tutorials for gfx there: http://brand107.home.comcast.net/pc-gpe/
The example above diden't work, because of some errors. This should work and it's also faster because there is only one 512*512 loop. (but it is still very slow) -- Dino Patti
Note that you don't have to use imagecolorallocate to draw pixels. Instead, you can assign colors directly, which is much faster as well:
imagesetpixel ($image, $x, $y, IMG_COLOR_BRUSHED);
Re: imagecreatefromtga() .. I just did some testing with what I think are valid Targa-24 and Targa-32 bit images, and modified the inner logic as follows: The red and blue tint issue seems to be fixed by this...
here's my version of imagecreatefromtga() that's been tested to work for targa 16 .. adapted from offering by zehao dot chang at gmail dot com function imagecreatefromtga($filename) { $data = file_get_contents($filename); // Extract header information $string_length = fileint($data, 1, 1); $data_type = fileint($data, 2, 1); $width = fileint($data, 12, 2); $height = fileint($data, 14, 2); $bits_per_pixel = fileint($data, 16, 1); $bytes_per_pixel = (int) $bits_per_pixel / 8; // Currently only supporting RGB Data type switch ($data_type) // Header information taken from http://astronomy.swin.edu.au/~pbourke/dataformats/tga/ { case 2: // Uncompressed RGB image break; case 0: // No attached image data case 1: // Uncompressed color-mapped image case 3: // Uncompressed black and white image case 9: // Runlength encoded color-mapped image case 10: // Runlength encoded RGB image case 11: // Compressed black and white image case 32: // Compressed color-mapped data, using Huffman, Delta, and runlength encoding case 33: // Compressed color-mapped data, using Huffman, Delta, and runlength encoding. 4-pass quadtree-type process default: return NULL; // No support for any of these types } // Compute things we need from the header information $pointer = 18 + $string_length; $x = 0; $y = $height - 1; $image = imagecreatetruecolor($width, $height); while ($pointer > 10; $g = ($word & 0x03E0) >> 5; $b = ($word & 0x001F); imagesetpixel($image, $x, $y, $r
Sorry for the long intro of my function, but i just want to tell how it works and - how silly sometimes the ideas are to make such functions. Have fun ;D Have fun ;D
@ Scott Evernden Scott, your function works great for uncompressed TGA image files, except the results for TGA 32 with alpha don't come out right, at least in my tests. If the alpha is all white, the resulting image comes out with a red tint. If black, the resulting image has a blue tint. I don't know how to make it just ignore the alpha, but that would be handy...
This code generate a simple colortable - not a very acurate one (it would be good to define fade of color - more fading)
I looked, but was unable to find any example code to watermark an image with a watermark that contained alpha transparency. So the following class does just that. As a parameter, it takes 2 image objects: the main image, and the watermark image (which can be a gif, png, whatever) - and optionally, an alpha setting (0-100% alpha for the watermark image). It then creates and returns a new image with the alpha-transparent watermark imposed, center-aligned, over the larger image.
I was looking for a way to actually DELETE pixels or squares or parts of an image from an image resource, and at first I thought imagesetpixel would do the trick. Unfortunately, it merely paints over that one pixel, and as far as I knew, php didn't have any native way of deleting sections out of your image - so this little method should take care of deleting rectangular parts of your pictures! function deleteRectangle(&$oldImage,$leftX,$leftY,$rightX,$rightY) { // Since php has no native way of delete parts of images // We have to divide the image into four different parts and then copy them manually to a new // image $xSize = imagesx($oldImage); $ySize = imagesy($oldImage); // Divides the image into four sections to copy $imagesection = array(); $imagesection[] = array(0,0,$leftX,$ySize); $imagesection[] = array($leftX,0,$rightX+1,$leftY); $imagesection[] = array($leftX,$rightY+1,$rightX+1,$ySize); $imagesection[] = array($rightX+1,0,$xSize,$ySize); // Create the new, copied image $newImage = imagecreatetruecolor($xSize,$ySize); // Vital for transparency imagesavealpha($newImage,true); // Fills the background a transparent color $transparentBackground = imagecolorallocatealpha($newImage,255,255,255,127); imagefill($newImage,0,0,$transparentBackground); // Copies each of the four imagesections into their respective old positions for($i = 0;$i An example of usage might be:
This snippet creates a gradient images depending on the value of RGB components. Gradients allow your page to have a shadow effect.
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)