相关疑难解决方法(0)

php imagecopyresampled质量差

我有一个PHP脚本保存原始图像,然后调整大小 - 一个缩略图和一个较大的图像供Web查看.这种效果很好,除了一些图像质量很差.它似乎是用非常低的颜色托盘保存的.你可以在http://kalpaitch.com/index.php?filter=white看到结果- 点击标题为'white white white'的第一个缩略图

以下是用于图像重采样的代码:

function resizeImg($name, $extension, $size1, $size2) {
if (preg_match('/jpg|jpeg|JPG|JPEG/',$extension)){
    $image = imagecreatefromjpeg($name);
}
if (preg_match('/gif|GIF/',$extension)){
    $image = imagecreatefromgif($name);
}

$old_width = imageSX($image);
$old_height = imageSY($image);
$old_aspect_ratio = $old_width/$old_height; 

if($size2 == 0){
    $new_aspect_ratio = $old_aspect_ratio;
    if($old_width > $old_height){
        $new_width = $size1;
        $new_height = $new_width / $old_aspect_ratio;
    } else {
        $new_height = $size1;
        $new_width = $new_height * $old_aspect_ratio;
    }
} elseif($size2 > 0){
    $new_aspect_ratio = $size1/$size2;
    //for landscape potographs
    if($old_aspect_ratio >= $new_aspect_ratio) {
        $x1 …
Run Code Online (Sandbox Code Playgroud)

php image

11
推荐指数
1
解决办法
2万
查看次数

提高PHP GD生成图像的质量

我将开始使用GD库在PHP中构建地图生成器.我使用lib生成了一些图像,但它们没有很好的质量.我只想知道有一些方法可以提高图像的质量.

生成的图像是:

img

我的代码是:

<?php

$canvas = imagecreate(800, 350);

imagecolorallocate($canvas, 255, 255, 255);

$pink = imagecolorallocate($canvas, 255, 105, 180);
$white = imagecolorallocate($canvas, 255, 255, 255);
$green = imagecolorallocate($canvas, 132, 135, 28);

imagestring( $canvas, 20, 290, 25, "Quality is not the best :(", $green );
function drawlinebox($x1, $y1, $x2, $y2, $height, $color){
    global $canvas;
    imagesetthickness ( $canvas, 1 );
    for ($i=1; $i < $height; $i++){
        imageline( $canvas, $x1, $y1, $x2, $y2, $color );
        $y1++; $y2++;
    }
}

drawlinebox(20, 20, 780, 300, 30, …
Run Code Online (Sandbox Code Playgroud)

php gd image

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

image ×2

php ×2

gd ×1