亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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

標簽:
PHP

<?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;
?>


<?php

$filename'img/example.png';

// ob_start();

// $im = imagecreatefrompng($filename);

// imagepng($im);

// $file = ob_get_contents();

// ob_end_clean();

$filefile_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;

$posstrpos($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;

?>




點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消