【发布时间】:2012-05-03 22:33:42
【问题描述】:
我有一个页面,仅用于打印,其中一些图像是通过我的脚本上传的。它似乎总是将图像降低到 72 dpi,而不管我为质量设置的 imagejpeg() 和 imagepng()。
我在 git hub 上使用过我自己的个人脚本和这个
https://github.com/maxim/smart_resize_image
我希望获得一些关于将 dpi 保持在原始 300dpi 的指导。
这是我自己的个人脚本
if (!empty($_FILES['image']['name'])) //checking if file upload box contains a value
{
$saveDirectory = 'pics/'; //name of folder to upload to
$tempName = $_FILES['image']['tmp_name']; //getting the temp name on server
$fileName1 = $_FILES['image']['name']; //getting file name on users computer
$count = 1;
do{
$location = $saveDirectory . $_GET['section'] . $count . $fileName1;
$count++;
}while(is_file($location));
if (move_uploaded_file($tempName, $location)) //Moves the temp file on server
{ //to directory with real name
$image = $location;
// Get new sizes
list($width, $height, $type) = getimagesize($image); //gets information about new server image
$framewidth = 932;
$frameheight = 354;
$realwidth = $width; //setting original width and height
$realheight = $height;
// Load
$file1new = imagecreatetruecolor($framewidth, $frameheight); //creates all black image with target w/h
if($type == 2){
$source = imagecreatefromjpeg($image);
imagecopyresampled($file1new, $source , 0, 0, 0, 0, $framewidth, $frameheight, $realwidth, $realheight);
}
elseif($type == 3){
$source = imagecreatefrompng($image);
imagecopyresampled($file1new, $source , 0, 0, 0, 0, $framewidth, $frameheight, $realwidth, $realheight);
}
else{
echo "Wrong file type";
}
if($type == 2){
//creates jpeg image from file1new for file1 (also retains quality)
imagejpeg($file1new, $image,100);
//frees space
imagedestroy($file1new);
}
elseif($type == 3){
//creates png image from file1new for file1 (also retains quality)
imagepng($file1new, $image,10);
//frees space
imagedestroy($file1new);
}
else{
echo "Wrong file type";
}
}
else
{
echo '<h1> There was an error while uploading the file.</h1>';
}
}
}
编辑:即使 dpi 不是答案,正如我所看到的 jpgs 具体不会保留该信息。我需要一些方法来保持这些图像非常清晰和清晰。
【问题讨论】:
-
ImageMagick 是否也表现出这种行为?也可以试试看。
-
我还没有尝试过任何图像魔法。我现在正在调查它。 (我以前从未使用过)。
-
我已经放弃了 GD 转而使用 imagick,它真是太棒了,你可以找到很多例子来进行图像处理,你从来不知道这么简单......当然,如果它不能做你想做的事描述它仍然很烂;-)
-
我正在研究它,但 ImageMagick 对我来说并不是一个真正的选择。不过,我安装了最新版本的 GD,并且正在使用us3.php.net/manual/en/function.imageconvolution.php#104006 此处的技术,但是虽然我的图像在屏幕上的显示效果要好十倍,但在打印时它们仍然是像素化的。在进行了一些数学运算之后,根据以英寸为单位的宽度和高度以及图像被报告为多少像素,似乎图像是 96dpi 而不是原始的 300dpi。 300 像素 X 450 像素,3.125 英寸 X 4.688 英寸。
-
我还有一个新的上传脚本,和我最初发布的没有太大区别,但确实有一些改进。如果您想发布它,我可以将其添加到我的原始帖子中。
标签: php upload resolution