03 3 月

PHP 使用GD函式庫更改圖片DPI

<?php
//Get jpeg image contents
ob_start();
imagejpeg($image, “”, 100);
$image = ob_get_contents();
ob_end_clean();

//Or read jpeg image
$image = file_get_contents($file);

//Replace header image info to set DPI as units and the density for X and Y
//First parameter are units for X and Y densities (0x00 No units, 0x01 DPI, 0x02 DPC)
//Second parameter is the X density
//Third parameter is the Y density
$image = substr_replace($image, pack(“Cnn”, 0x01, 300, 300), 13, 5); // 預設72DPI改成300DPI

header(“Content-type: image/jpeg”);
header(‘Content-Disposition: attachment; filename=”‘.basename($file).'”‘);

echo $image;
?>

Share this

Leave a reply

發表迴響