如何在php中锐化base64编码的图像

时间:2016-03-14 10:50:12

标签: php image gd

是否有任何库(最好是免费的)可用于在php中锐化base64 ecoded图像。

您好我在php中使用mpdf生成一个pdf文件,显示一个人签名的base64编码图像。

问题是图像看起来不太清晰或不清晰。我受限于图像的大小(尺寸),因为我需要每行显示10个图像。

目前我使用以下代码输出图像:

<img src="data:image/png;base64,'. $pieces[0] .'" height="15" width="60" />

$ pieces [0]是来自mySQL的字符串(例如iVBORw0KGgoAAAANSUh ....)

2 个答案:

答案 0 :(得分:0)

干预图像是我知道处理图像的最佳工具。

您可以在其中输入几乎任何类型的图像(甚至是base64),并随意使用它。

请参阅此处的文档http://image.intervention.io/api/make

答案 1 :(得分:0)

我使用ImageMagick。

ImageMagick

这是您可以修改的基本功能。

function imagick_sharpen_resized_files($resized_file) {

    $image = new Imagick($resized_file); 

    $size = @getimagesize($resized_file);

    if (!$size)

        return new WP_Error('invalid_image', __('Could not read image size.'), $file);

    list($orig_w,$orig_h,$orig_type) = $size;



    // We only want to use our sharpening on JPG files

    switch($orig_type) {

        case IMAGETYPE_JPEG:



    // Automatic Contrast Leveling

    if (get_option('AutoConLev')==true) {

        $image->normalizeImage();

    }



    // Sharpen the image (the default is via the Lanczos algorithm)

        $image->unsharpMaskImage(get_option('Radius'),get_option('Sigma'),get_option('Sharpening'),get_option('Threshold'));



    // Store the JPG file, with as default a compression quality of 92 (default WordPress = 90, default ImageMagick = 85...)

        $image->setImageFormat("jpg");

        $image->setImageCompression(Imagick::COMPRESSION_JPEG);

        $image->setImageCompressionQuality(get_option('CompressionQuality'));

        $image->writeImage($resized_file); 



            break;

        default:

            return $resized_file;

    }   



    // Remove the JPG from memory

    $image->destroy();



    return $resized_file;

}

希望这有帮助,

相关问题