【发布时间】:2022-12-30 22:09:48
【问题描述】:
我有一个函数接受一个 10 个字符的字符串并渲染一个 300dpi PNG 准备打印。 它工作得很好,但是当使用 imagecropauto() 函数时 - 原始分辨率丢失,我最终得到一个 96dpi 的文件。
$string = "URBANWARFARE";
header('Content-type: image/png');
header("Cache-Control: no-store, no-cache");
header('Content-Disposition: attachment; filename="name.png"');
$img = imagecreate(4200, 420); // Sets the size of my canvas
imageresolution($img, 300, 300); // Sets the DPI to 300dpi on X and Y
imagealphablending($img, FALSE);
imagesavealpha($img, TRUE);
$transparent = imagecolorallocatealpha($img, 255, 255, 255, 127); // create transparency
imagefill($img,0,0,$transparent); // apply the transparency to the image
//imagecolortransparent($img,$transparant);
$textColor = imagecolorallocate($img, 255, 255, 255); // White Text Colour
$font = "./Bloomsbury-Sans.ttf"; // Set the font
imagettftext($img, 380, 0, 0, 410, $textColor, $font, $string); // Draw the text
$cropped = imagecropauto($img,IMG_CROP_DEFAULT); // crop the dead space around the text
imagepng($img); // 300dpi
imagepng($cropped); // 96dpi
imagedestroy($img);
imagedestroy($cropped);
有趣的是 - 如果我将文件设置为 72dpi - 该文件仍然作为 96dpi 文件从 imagecropauto() 中出来。我在文档中看不到任何提及 - 这似乎是一个非常奇怪的解决方案?
【问题讨论】:
标签: php image-resolution