【问题标题】:Converting Image form 300 DPI to 72 DPI an resize with and height将图像形式 300 DPI 转换为 72 DPI 并调整大小和高度
【发布时间】:2015-09-17 14:17:05
【问题描述】:

我正在寻找 php 中的解决方案,将我的图像从 300 DPI 转换为 72 DPI。 这样脚本首先检查 img == 72 DPI 是否不执行任何其他转换为 72 DPI。然后检查大小并调整图像大小。

类似的东西。

if ($image(dpi) > 72 dpi) {
   convert to 72 DPI;
}
else {
}

【问题讨论】:

  • 你有 ImageMagick 模块还是可以安装它?
  • 没有。但我看了一下模块以及如何安装它。

标签: php image-resizing dpi


【解决方案1】:

使用下面的代码行将图像 dpi 从 300 转换为 72 dpi:

$filename = "Enter path of the image which you want to use";

$image = file_get_contents($filename);
$image =substr_replace($image, pack("cnn", 1, 72, 72), 13, 5); file_put_contents($filename,$image);

【讨论】:

    【解决方案2】:

    要将图像转换为不同的分辨率,您需要 ImageMagick。

    $img = new Imagick($imgname);
    if ($img) {
      $width=$img->getImageWidth();
      $height=$img->getImageHeight();
      $res=$img->getImageResolution();
      $colorspace=$img->getImageColorspace();
    
      $resx=$res['x'];
      $resy=$res['y'];
      echo 'Image is '.$width.'x'.$height.' resolution: '.$resx.'x'.$resy.' colorspace='.$colorspace.'='.$colorspace_array[$colorspace];
      $cmw=($width/$resx)*2.54;
      $cmh=($height/$resy)*2.54;
      echo 'Image is '.$cmw.'cm x '.$cmh.'cm';
    
      // creating 72dpi version
      $w72=round($width*72/$resx);
      $h72=round($height*72/$resy);
      if ($w72>$width || $h72>$height) {
        $w72=$width;
        $h72=$height;
      }
    
      $img->resizeImage($w72,$h72,imagick::FILTER_QUADRATIC,1);
      $img->writeImage('newimage.png');
    
    } else {
      die('Unknown image format');
    }
    

    【讨论】:

      【解决方案3】:

      试试这个:

      $image = imagecreatefromjpeg($source);
      $image = imagecreatefromgif($source);
      $image = imagecreatefrompng($source);
      
      imagejpeg($source_image, $destination_image, $quality); //i'd say keep quality up to 70. anything over that is too much for no reason
      

      我的建议只是限制上传大小,您的问题就解决了。

      但要回答您的问题,请使用 ImageMagick:

      $img = new Imagick();
      $img->setResolution(25,25);
      

      【讨论】:

      • 这没有回答问题。
      • 我限制了上传:) 但这就是问题所在,他们不明白为什么需要转换图像。所以我正在考虑让他们尽可能轻松:)
      猜你喜欢
      • 1970-01-01
      • 2019-05-10
      • 2018-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 1970-01-01
      相关资源
      最近更新 更多