- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我试图在旋转图像(许多图像$im
)后复制图像(到$img
),但我得到了奇怪的行为。一旦我取消注释 //$img =
行,我只会在最终输出中获得旋转图像。我可以旋转内部 $im
并将其复制到最终图像 $img
吗?
<?php
$height = 80;
$width = 300;
$img = imagecreate($width, $height);
$c = imagecolorallocate ($img , 135, 135, 135);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));
for($i=0; $i<=5; $i++){
$im = imagecreatetruecolor(35, 35);
$gry = imagecolorallocate($im, 135, 135, 135);
$wht = imagecolorallocate($im, 255, 255, 255);
$j = mt_rand(0, 1);
$ch = mt_rand(0,1)?chr(rand(65, 90)):chr(rand(97, 122));
if($j == 0){
imagefill($im, 0, 0, $wht);
imagefttext($im, 20, 0, 3, 21, $gry, 'AHGBold.ttf', $ch);
//$img = imagerotate($im, mt_rand(0,10)-5, $wht);
}else{
imagefill($im, 0, 0, $gry);
imagefttext($im, 20, 0, 3, 21, $wht, 'AHGBold.ttf', $ch);
//$img = imagerotate($im, mt_rand(0,10)-5, $gry);
}
imagecopyresampled($img, $im, 5 + $i*42, $height/2 - 12, 0, 0, 40, 40, 25, 25);
}
header('Content-type: image/png');
imagepng($img);
最佳答案
改变
$img = imagerotate($im, mt_rand(0,10)-5, $wht);
和
$img = imagerotate($im, mt_rand(0,10)-5, $gry);
到
$im = imagerotate($im, mt_rand(0,10)-5, $wht);
和
$im = imagerotate($im, mt_rand(0,10)-5, $gry);
在 imagerotes
不起作用的情况下,您可以使用以下函数来旋转图像:
function imagerotateEquivalent(&$srcImg, $angle, $bgcolor, $ignore_transparent = 0)
{
$srcw = imagesx($srcImg);
$srch = imagesy($srcImg);
if($angle == 0) return $srcImg;
// Convert the angle to radians
$theta = deg2rad ($angle);
// Calculate the width of the destination image.
$temp = array ( rotateX(0, 0, 0-$theta),
rotateX($srcw, 0, 0-$theta),
rotateX(0, $srch, 0-$theta),
rotateX($srcw, $srch, 0-$theta)
);
$minX = floor(min($temp));
$maxX = ceil(max($temp));
$width = $maxX - $minX;
// Calculate the height of the destination image.
$temp = array ( rotateY(0, 0, 0-$theta),
rotateY($srcw, 0, 0-$theta),
rotateY(0, $srch, 0-$theta),
rotateY($srcw, $srch, 0-$theta)
);
$minY = floor(min($temp));
$maxY = ceil(max($temp));
$height = $maxY - $minY;
$destimg = imagecreatetruecolor($width, $height);
imagefill($destimg, 0, 0, imagecolorallocate($destimg, 0,255, 0));
// sets all pixels in the new image
for($x=$minX;$x<$maxX;$x++) {
for($y=$minY;$y<$maxY;$y++)
{
// fetch corresponding pixel from the source image
$srcX = round(rotateX($x, $y, $theta));
$srcY = round(rotateY($x, $y, $theta));
if($srcX >= 0 && $srcX < $srcw && $srcY >= 0 && $srcY < $srch)
{
$color = imagecolorat($srcImg, $srcX, $srcY );
}
else
{
$color = $bgcolor;
}
imagesetpixel($destimg, $x-$minX, $y-$minY, $color);
}
}
return $destimg;
}
function rotateX($x, $y, $theta){
return $x * cos($theta) - $y * sin($theta);
}
function rotateY($x, $y, $theta){
return $x * sin($theta) + $y * cos($theta);
}
我从 a note in php.net 得到上面的代码
关于php - imagecopyresampled 旋转图像后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31109771/
我在使用 imagecopyresampled 时遇到了一些问题,主要是图像没有正确缩放,图像位置错误,边缘有黑色边框。 我设置了以下变量 $tW = $width; // Original
我有以下工作正常: 用户上传一张图片,然后使用 imagecopyresampled 和 imagejpeg 调整图片大小(保持比例),使其适合裁剪 DIV。 然后用户使用 JCrop 裁剪图像,然后
因此,我尝试使用 imagecopyresampled 来裁剪照片的一部分,这样我就不必担心我的用户上传到我的网站的照片比预期的要大。不幸的是,我还没有弄清楚为什么 imagecopyresample
我有一个调整大小的图像脚本,它采用 130x81 图像并将其添加到 130x130 图像,当 imagecopyresampled 函数运行时,它会在剩余的空间中添加黑色背景,即使基本图像是白色的。下
我想在另一个大图像上添加一个小图像作为不透明的水印。 我正在使用 imagecopyresampled 将图像放在另一个图像上。 但是,如何为水印图像提供不透明度。 请帮帮我。 我正在使用这个简单的示
我有一个 php 脚本,它可以保存原始图像,然后调整它的大小 - 一个缩略图和一个较大的图像供网络查看。这很好用,除了一些图像质量很差。它似乎是用一个非常低的颜色托盘保存的。您可以在 http://k
我试图在旋转图像(许多图像$im)后复制图像(到$img),但我得到了奇怪的行为。一旦我取消注释 //$img = 行,我只会在最终输出中获得旋转图像。我可以旋转内部 $im 并将其复制到最终图像 $
我正在创建一个需要使用 jQuery 缩放脚本的网站。问题是我需要管理员上传的原始文件的 4 倍大图像。我写的代码是: $allowedExts = array("jpeg", "jpg"); $ex
$image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); i
我有以下代码: $fullImg = $_POST['img']; $avatar_name = $log_username.md5(uniqid()).'_avatar.jpg'; $avatar_
imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x
我想使用 imagecreatetruecolor 裁剪图像,它总是裁剪它留下黑色空间,或者缩放太大。我希望图像恰好是 191px 宽和 90px 高,所以我还需要调整图像的大小以及裁剪,因为比例必须
我正在尝试从正常尺寸的图像创建 2 个裁剪缩略图(60x60 和 150x150)。除了裁剪之外,一切都很好,裁剪不起作用。该部分正在生成一个缩略图,右侧有一条黑线,如下所示: ...........
我有一个脚本可以拍摄图像,并且在重新采样时将短尺寸(宽度或高度)居中放置在方形彩色背景上。这适用于具有较长 WIDTH 的图像,但由于某种原因,任何具有较长 HEIGHT 的图像结果是分离背景填充 -
将图片上传到我的网站后,图片正在调整大小。我正在使用 imagecreatefromjpeg 和 imagecopyresampled 函数。我注意到颜色与原始图像中的颜色不同。 从这里你可以看出区别
好吧,我以为我理解这个功能,但我对这个有一个完整的心理障碍。 我想从 800x536 的照片创建尺寸为 75x75 的裁剪缩略图。 imagecopyresampled 函数有 10 个可能的参数。我
我正在我的网站上构建一个图片上传功能,让用户可以将任何尺寸的图片上传到网站。此图片会自动调整为缩略图大小。我浏览了一些代码,我看到一些代码使用 imagecopyresampled() 函数来调整大小
我需要一个脚本,它可以在提供的图像上制作圆角透明角。我找到了一个,除了一件事外效果很好:应用的角看起来不光滑。 imageantialias()自 PHP is running on Debian 后
我正在使用jquery file upload脚本并已成功将主图像上传到 Amazon S3。我现在正在尝试更换多个图像尺寸以上传到 S3 中的子文件夹或对象。 在 UploadHandler.php
这些似乎都在做同样的事情。各自的优点/缺点是什么。 imagecopyresized() 对比 imagecopyresampled() 对比 imagecopy()。 我正在调整用户提交的图像的大小
我是一名优秀的程序员,十分优秀!