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

How can I sharpen base64 encoded image in php

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

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

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

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

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

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

Intervention Image 是我所知道的处理图像的最佳工具。

您可以在其中输入几乎任何类型的图像(甚至是 base64)并用它做您想做的事。

在此处查看文档 http://image.intervention.io/api/make

我用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;

}

希望这对您有所帮助,

蒂姆