gd 相关问题

GD是一个开源代码库,用于程序员动态创建图像。 GD是用C语言编写的,“包装器”可用于Perl,PHP和其他语言。 GD创建PNG,JPEG和GIF图像以及其他格式。 GD通常用于动态生成图表,图形,缩略图和大多数其他内容。虽然不限于在网络上使用,但GD的最常见应用涉及网站开发。

删除python枕头图片评论

自从将 python3pillow 升级到版本 10.3.0 后,我发现在调整图像大小时,它会在我的 .jpg 中添加一条以前从未存在过的注释(相对于一年左右前,但我不知道的...

回答 1 投票 0

使用 Perl GD 更改像素颜色

我正在尝试更改 PNG 文件中某些像素的颜色。作为测试,以下脚本应读取 (256x256) PNG 文件,在其上绘制红色对角线,并将生成的图像写入文件。有一个

回答 1 投票 0

通过 GD 库函数使用自定义印地语字体时,图像上的叠加文本未正确渲染

我正在尝试使用 php 中的 GD 库将覆盖文本添加到图像中,虽然它非常适合英语字符,但当文本为印地语时,我遇到渲染问题,即使字体...

回答 1 投票 0

Amazon S3 png 文件没有透明度

我不确定我做错了什么,但上传到 S3 Amazon 存储桶的 PNG 文件显示白色而不是透明,即使本地文件确实显示透明度。这是我所拥有的: ...

回答 1 投票 0

php gd - 多色图像ttftext

我正在尝试通过 imagettftext 放置多色文本。 我尝试逐字绘制,但字距调整很差。 这是我的代码: $usrname_split = str_split("文本"); $onecharwidth =

回答 1 投票 0

将Exif数据写回到GD图库旋转的图像中

当尝试通过 GD 图像旋转图像后将原始 exif 数据附加回图像时,我遇到了麻烦。 我如何旋转图像 旋转图像 = gdImageRotateInterpolated(图像, (360-rotationDeg)%360, 0);

回答 1 投票 0

GD 图像模糊 Opencart

我在 Opencart 中进行 GD 图像处理时遇到了这个问题,它在调整大小后会创建非常糟糕的模糊图像。到目前为止我所尝试的一切都没有帮助。 下面是 image.php 的代码 我在 Opencart 中进行 GD 图像处理时遇到了这个问题,它在调整大小后会创建非常糟糕的模糊图像。到目前为止我所尝试的一切都没有帮助。 下面是 image.php 的代码 <?php class Image { private $file; private $image; private $info; public function __construct($file) { if (file_exists($file)) { $this->file = $file; $info = getimagesize($file); $this->info = array( 'width' => $info[0], 'height' => $info[1], 'bits' => $info['bits'], 'mime' => $info['mime'] ); $this->image = $this->create($file); } else { exit('Error: Could not load image ' . $file . '!'); } } private function create($image) { $mime = $this->info['mime']; if ($mime == 'image/gif') { return imagecreatefromgif($image); } elseif ($mime == 'image/png') { return imagecreatefrompng($image); } elseif ($mime == 'image/jpeg') { return imagecreatefromjpeg($image); } } public function save($file, $quality = 100) { $info = pathinfo($file); $extension = strtolower($info['extension']); if (is_resource($this->image)) { if ($extension == 'jpeg' || $extension == 'jpg') { imagejpeg($this->image, $file, $quality); } elseif($extension == 'png') { imagepng($this->image, $file); } elseif($extension == 'gif') { imagegif($this->image, $file); } imagedestroy($this->image); } } /** * * @param width * @param height * @param default char [default, w, h] * default = scale with white space, * w = fill according to width, * h = fill according to height * */ public function resize($width = 0, $height = 0, $default = '') { if (!$this->info['width'] || !$this->info['height']) { return; } $xpos = 0; $ypos = 0; $scale = 1; $scale_w = $width / $this->info['width']; $scale_h = $height / $this->info['height']; if ($default == 'w') { $scale = $scale_w; } elseif ($default == 'h'){ $scale = $scale_h; } else { $scale = min($scale_w, $scale_h); } if ($scale == 1 && $scale_h == $scale_w && $this->info['mime'] != 'image/png') { return; } $new_width = (int)($this->info['width'] * $scale); $new_height = (int)($this->info['height'] * $scale); $xpos = (int)(($width - $new_width) / 2); $ypos = (int)(($height - $new_height) / 2); $image_old = $this->image; $this->image = imagecreatetruecolor($width, $height); if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') { imagealphablending($this->image, false); imagesavealpha($this->image, true); $background = imagecolorallocatealpha($this->image, 255, 255, 255, 127); imagecolortransparent($this->image, $background); } else { $background = imagecolorallocate($this->image, 255, 255, 255); } imagefilledrectangle($this->image, 0, 0, $width, $height, $background); imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']); imagedestroy($image_old); $this->info['width'] = $width; $this->info['height'] = $height; } public function watermark($file, $position = 'bottomright') { $watermark = $this->create($file); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); switch($position) { case 'topleft': $watermark_pos_x = 0; $watermark_pos_y = 0; break; case 'topright': $watermark_pos_x = $this->info['width'] - $watermark_width; $watermark_pos_y = 0; break; case 'bottomleft': $watermark_pos_x = 0; $watermark_pos_y = $this->info['height'] - $watermark_height; break; case 'bottomright': $watermark_pos_x = $this->info['width'] - $watermark_width; $watermark_pos_y = $this->info['height'] - $watermark_height; break; } imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40); imagedestroy($watermark); } public function crop($top_x, $top_y, $bottom_x, $bottom_y) { $image_old = $this->image; $this->image = imagecreatetruecolor($bottom_x - $top_x, $bottom_y - $top_y); imagecopy($this->image, $image_old, 0, 0, $top_x, $top_y, $this->info['width'], $this->info['height']); imagedestroy($image_old); $this->info['width'] = $bottom_x - $top_x; $this->info['height'] = $bottom_y - $top_y; } public function rotate($degree, $color = 'FFFFFF') { $rgb = $this->html2rgb($color); $this->image = imagerotate($this->image, $degree, imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); $this->info['width'] = imagesx($this->image); $this->info['height'] = imagesy($this->image); } private function filter($filter) { imagefilter($this->image, $filter); } private function text($text, $x = 0, $y = 0, $size = 5, $color = '000000') { $rgb = $this->html2rgb($color); imagestring($this->image, $size, $x, $y, $text, imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); } private function merge($file, $x = 0, $y = 0, $opacity = 100) { $merge = $this->create($file); $merge_width = imagesx($image); $merge_height = imagesy($image); imagecopymerge($this->image, $merge, $x, $y, 0, 0, $merge_width, $merge_height, $opacity); } private function html2rgb($color) { if ($color[0] == '#') { $color = substr($color, 1); } if (strlen($color) == 6) { list($r, $g, $b) = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]); } elseif (strlen($color) == 3) { list($r, $g, $b) = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]); } else { return false; } $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); } } ?> 正如您所看到的,质量已经设置为 100 ,所以这没有帮助。 我尝试用 resample 替换 resize - 但这没有产生可见的结果。 然而,我发现了这个建议(下面的代码)来锐化图像,不幸的是我不知道如何以及在哪里使用它。特别是因为原始代码处理多种图像类型。请帮忙把它放在正确的地方。 { $matrix = array( array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1), ); $divisor = array_sum(array_map('array_sum', $matrix)); $offset = 0; imageconvolution($image, $matrix, $divisor, $offset); return $image; } 此外,如果您有其他建议来改进此代码,我们将不胜感激!我认为这适用于整个 Opencart 社区,因为这个问题已经讨论过很多次了,但目前还没有发布可行的解决方案。 quality参数仅适用于.jpeg图像。 要锐化图像,您可以在 imageconvolution() 函数中应用 resize() 代码。 public function resize($width = 0, $height = 0, $default = '') { if (!$this->info['width'] || !$this->info['height']) { return; } $xpos = 0; $ypos = 0; $scale = 1; $scale_w = $width / $this->info['width']; $scale_h = $height / $this->info['height']; if ($default == 'w') { $scale = $scale_w; } elseif ($default == 'h') { $scale = $scale_h; } else { $scale = min($scale_w, $scale_h); } if ($scale == 1 && $scale_h == $scale_w && $this->info['mime'] != 'image/png') { return; } $new_width = (int)($this->info['width'] * $scale); $new_height = (int)($this->info['height'] * $scale); $xpos = (int)(($width - $new_width) / 2); $ypos = (int)(($height - $new_height) / 2); $image_old = $this->image; $this->image = imagecreatetruecolor($width, $height); if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') { imagealphablending($this->image, false); imagesavealpha($this->image, true); $background = imagecolorallocatealpha($this->image, 255, 255, 255, 127); imagecolortransparent($this->image, $background); } else { $background = imagecolorallocate($this->image, 255, 255, 255); } imagefilledrectangle($this->image, 0, 0, $width, $height, $background); imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']); //Image Sharpening Code $matrix = array( array(0.0, -1.0, 0.0), array(-1.0, 5.0, -1.0), array(0.0, -1.0, 0.0) ); $divisor = array_sum(array_map('array_sum', $matrix)); $offset = 0; imageconvolution($this->image, $matrix, $divisor, $offset); // End Image Sharpening Code imagedestroy($image_old); $this->info['width'] = $width; $this->info['height'] = $height; } 参考资料: 使用 PHP gd 库提高图像质量 http://adamhopkinson.co.uk/blog/2010/08/26/sharpen-an-image-using-php-and-gd/

回答 1 投票 0

调用未定义的函数 imagewebp()

我想知道为什么会出现此错误。我将 php 从 5.6.22 更新到 5.6.40,现在出现此错误。这在以前的版本中工作得很好,但突然就变成这样了。 致命错误:Ca...

回答 3 投票 0

简单的 php 图像旋转不会保存新的旋转

我看到很多人问这个问题,但他们都是根本无法让自己的形象旋转的人。我可以让旋转工作,我的问题是它不会保存新图像

回答 1 投票 0

在 PHP 中调整 PNG 图像大小

调整 PNG 大小时没有图像显示,但以下代码适用于 JPEG。 列表($width_orig,$height_orig)= getimagesize($文件名); $ratio_orig = $width_orig/$height_orig; 我...

回答 5 投票 0

我正在尝试使用 PHP 中的 GD 库使图像透明,但运行以下代码,只有一部分是透明的

我正在尝试使用 PHP 中的 GD 库使图像透明,但运行以下代码,只有一部分是透明的。 $image = imagecreatefrompng("$second"); imagealphablending($image,

回答 2 投票 0

干预laravel中镜像安装问题

我在 Windows 操作系统和 laravel 10 上安装干预/映像包时遇到问题。我按照以下步骤操作: 在 VS Code 的项目目录终端中输入以下命令: 作曲家

回答 1 投票 0

图像复制并不总是有效

我遇到 imagecopy 问题,即使工作示例和非工作示例中都有 PNG,$url 变量上的某些图像也不会出现。 $local 变量加载透明图像

回答 2 投票 0

php imagecopyresized vs imagecopyresampled vs imagecopy 优点/缺点

这些似乎都在做同样的事情。 各自的优点/缺点是什么。 imagecopyresized() vs imagecopyresampled() vs imagecopy()。 我正在调整用户提交的图像的大小。 所以我有一个图像外壳创建...

回答 1 投票 0

GD 扩展图像调整大小不适用于手机

我有一个网站,其中包含一个表单,允许用户将图像从其设备上传到网站以将其用于特定目的。我现在在 PHP 中使用 GD 扩展来压缩...

回答 1 投票 0

我无法让 PHP GD 图像大小调整脚本工作

我看过很多关于使用 PHP 和 GD 调整图像大小的视频,并且我已经剪切并粘贴了很多我被告知可以完成这项工作的代码,但我永远无法让图像脚本来调整大小甚至显示 i. ..

回答 1 投票 0

如何使用 Perl 和 GD 在另一张图像上绘制半透明形状?

我正在尝试使用 Perl 的 GD.pm 在现有图像上绘制半透明块。 我的代码如下所示: 使用严格; 使用GD; 我的 $img = GD::Image->new('cello.png'); GD::图像->trueColo...

回答 1 投票 0

使用 GDLibrary 合并图像

我希望你能帮助我。我正在尝试为 WordPress 编写一个函数,它将上传的图像与保存到主题目录中的另一个图像合并。本质上就是水印。我快到了,...

回答 2 投票 0

使用 PHP GD 扩展的不透明效果

我想知道使用 PHP GD 扩展在其他图像上绘制图像时是否可以产生“不透明”效果?是否有任何内置函数可以得到我想要的结果或者我...

回答 2 投票 0

不透明的水印图像

我正在尝试使用 PHP 和 GD 图像库向图像添加水印。我可以在指定的位置应用正确的不透明度设置的水印。 问题是我的水印本身...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.