Issue
Are there any libraries (preferably free) that I can use to sharpen base64 ecoded images in php.
Hi I am generating a pdf file using mpdf in php that shows base64 encoded image of a person's signature.
The problem is the images do not look very sharp or clear. I am constrained with the size(dimensions) of the image as I need to show 10 images per row.
Currently I output the image using the following bit of code:
<img src="data:image/png;base64,'. $pieces[0] .'" height="15" width="60" />
$pieces[0] is the string that comes from mySQL for example(iVBORw0KGgoAAAANSUh....)
Solution
I use ImageMagick.
Here is a base function you can modify.
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;
}
Hope this helps,
Tim
Answered By - STEAMworks Learning Center Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.