Tag: gd

比较2图像在PHP中

比较两张图片看是否是同一个文件很容易,把文件MD5扔了,但是用PHP GD来判断两张图片是否相同,甚至是合理的。 如果我们从哪里得到两者的区别,那全是白色的(id是白色还是黑色),那么现在我们就可以知道它们是同一张照片了吗? 另外注意:id喜欢知道是否有可能得到2张相同大小的图像来创build洋葱皮效果,1%的透明度为50%,另一种为50%。

PHP的GD使用一个图像来掩盖另一个图像,包括透明度

我正在尝试创build一个需要映像的PHP脚本: http://i.stack.imgur.com/eNvlM.png 然后应用一个PNG图像: http://i.stack.imgur.com/iJr2I.png 作为面具。 最终结果需要保持透明度: http://i.stack.imgur.com/u0l0I.png 如果可能的话,我想在GD中做到这一点,ImageMagick现在不是一个真正的select。 我将如何去做这件事? phalacee的post(在“PHP / GD,如何从一个图像复制到另一个圆?”)似乎沿着正确的线条,但我特别需要使用图像作为面具,而不是一个形状。

在PHP中裁剪图像

下面的代码很好地修剪图像,这是我想要的,但对于较大的图像,它也工作。 有没有什么办法“缩小图像” 理想情况下,我将能够在裁剪之前使每幅图像的大小大致相同,以便每次都能获得好的结果 代码是 <?php $image = $_GET['src']; // the image to crop $dest_image = 'images/cropped_whatever.jpg'; // make sure the directory is writeable $img = imagecreatetruecolor('200','150'); $org_img = imagecreatefromjpeg($image); $ims = getimagesize($image); imagecopy($img,$org_img, 0, 0, 20, 20, 200, 150); imagejpeg($img,$dest_image,90); imagedestroy($img); echo '<img src="'.$dest_image.'" ><p>';

imagecreatefrompng()使黑色背景而不是透明?

我使用PHP和GD库缩略图,但我的代码将png的透明度变成纯黑色,是否有解决scheme来改善我的代码? 这是我的PHP缩略图制造商代码: function cropImage($nw, $nh, $source, $stype, $dest) { $size = getimagesize($source); $w = $size[0]; $h = $size[1]; switch($stype) { case 'gif': $simg = imagecreatefromgif($source); break; case 'jpg': $simg = imagecreatefromjpeg($source); break; case 'png': $simg = imagecreatefrompng($source); break; } $dimg = imagecreatetruecolor($nw, $nh); $wm = $w/$nw; $hm = $h/$nh; $h_height = $nh/2; $w_height = $nw/2; […]

使用PHP的GDlib imagecopyresampled时,可以保留PNG图像透明度吗?

以下PHP代码段使用GD将浏览器上传的PNG调整为128×128。 它工作的很好,除了在我的情况下,原始图像中的透明区域被replace为纯色 – 黑色。 即使imagesavealpha设置,一些不太正确的。 在重采样图像中保留透明度的最佳方法是什么? $uploadTempFile = $myField[ 'tmp_name' ] list( $uploadWidth, $uploadHeight, $uploadType ) = getimagesize( $uploadTempFile ); $srcImage = imagecreatefrompng( $uploadTempFile ); imagesavealpha( $targetImage, true ); $targetImage = imagecreatetruecolor( 128, 128 ); imagecopyresampled( $targetImage, $srcImage, 0, 0, 0, 0, 128, 128, $uploadWidth, $uploadHeight ); imagepng( $targetImage, 'out.png', 9 );

PHP中有效的JPEG图像大小调整

什么是在PHP中调整大图像的最有效的方法? 我目前使用GDfunctionimagecopyresampled采取高分辨率的图像,并干净地resize他们的网页浏览的大小(大约700像素宽700像素高)。 这对于较小的(2 MB以下)照片效果很好,整个resize操作在服务器上的时间不到一秒钟。 但是,该网站最终将为可能上传图片大小为10 MB(或图片尺寸高达5000 x4000像素)的摄影师提供服务。 使用大图像进行这种resize操作会导致内存使用量大幅增加(较大的图像可能会使内存使用率超过80 MB)。 有没有办法使这个resize操作更有效率? 我应该使用一个替代图像库,如ImageMagick ? 现在,resize代码看起来像这样 function makeThumbnail($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality) { // Takes the sourcefile (path/to/image.jpg) and makes a thumbnail from it // and places it at endfile (path/to/thumb.jpg). // Load image and get image size. $img = imagecreatefromjpeg($sourcefile); $width = imagesx( $img ); $height = […]