//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;
?>
// $file = ob_get_contents(); // ob_end_clean(); $file= file_get_contents($filename); //数据块长度为9 $len= pack("N", 9); //数据块类型标志为pHYs $sign= pack("A*", "pHYs"); $sign= pack("A*", "pHYs"); //X方向和Y方向的分辨率均为300DPI(1像素/英寸=39.37像素/米),单位为米(0为未知,1为米) $data= pack("NNC", 300 * 39.37, 300 * 39.37, 0x01); //CRC检验码由数据块符号和数据域计算得到 $checksum= pack("N", crc32($sign. $data)); $phys= $len. $sign. $data. $checksum; $pos= strpos($file, "pHYs"); if($pos> 0) { //修改pHYs数据块 $file= substr_replace($file, $phys, $pos- 4, 21); } else{ //IHDR结束位置(PNG头固定长度为8,IHDR固定长度为25) $pos= 33; //将pHYs数据块插入到IHDR之后 $file= substr_replace($file, $phys, $pos, 0); } header("Content-type: image/png"); header('Content-Disposition: attachment; filename="'. basename($filename) . '"'); echo$file; ?> $filename= 'img/example.png';// ob_start();// $im = imagecreatefrompng($filename);// imagepng($im);



