douhao2153 2015-02-05 13:23
浏览 324
已采纳

调整PNG大小而不会降低质量和透明度

I have to resize images, cause we upload printable high res images and for the preview people dont need a 4000px+ image. Some images using the rgb color space "eci" and others using the color space srgb. The srgb files dont have any problems, but the eci looking a bit colourless than before. And when I upload a transparent image, its not perfect transparent. Is there any solution? When I resize and its a png image, I use following extra function.

private function imagetranstowhite($trans) {
    // Create a new true color image with the same size
    $w = imagesx($trans);
    $h = imagesy($trans);
    $white = imagecreatetruecolor($w, $h);

    // Fill the new image with white background
    $bg = imagecolorallocate($white, 255, 255, 255);
    imagefill($white, 0, 0, $bg);

    // Copy original transparent image onto the new image
    imagecopy($white, $trans, 0, 0, 0, 0, $w, $h);

    return $white;
}

Does anyone have a solution? Imagemagick instead of gdlib is fine too.

  • 写回答

2条回答 默认 最新

  • dozabg1616 2019-03-10 15:54
    关注

    For people with the same problem in the future. I solved it by stopped using imagegd and switched to ImageMagick. All images are still transparent and u can easily convert cmyk images to sRGB with the correct ICC profile

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境