【问题标题】:Jcrop: How to overcome low resolution images after cropping?Jcrop:裁剪后如何克服低分辨率图像?
【发布时间】:2016-06-27 23:42:24
【问题描述】:

我目前正在研究一种解决方案,我使用 jcrop 将图像裁剪为矩形,以便可以将其用作 3D 立方体的纹理(在 three.js 中) 并且我可以将裁剪区域保存为服务器上的图像。

这里的问题是,裁剪后的图像看起来不好,质量低。 一开始我还以为跟DPI有关,因为它保存在96 DPI,但是我上传的一些图片也有96 dpi并且质量很好。

我认为这与 jcrop 有关。有人知道这个问题或对 jcrop 有任何经验吗?还是应该使用其他插件?

Original Image

Cropped Image

【问题讨论】:

    标签: image dpi jcrop todataurl image-quality


    【解决方案1】:

    你为什么不使用 php 调整图像系统。 我在我的网站上使用它。

    查看演示调整壁纸大小(查看屏幕截图):Happy diwali wallpaper

    和原始壁纸(下载按钮以及页面下方的调整大小选项)diwali wallpaper

    你可以使用

    function resize($newWidth, $targetFile, $originalFile) {
    
    $info = getimagesize($originalFile);
    $mime = $info['mime'];
    
    switch ($mime) {
            case 'image/jpeg':
                    $image_create_func = 'imagecreatefromjpeg';
                    $image_save_func = 'imagejpeg';
                    $new_image_ext = 'jpg';
                    break;
    
            case 'image/png':
                    $image_create_func = 'imagecreatefrompng';
                    $image_save_func = 'imagepng';
                    $new_image_ext = 'png';
                    break;
    
            case 'image/gif':
                    $image_create_func = 'imagecreatefromgif';
                    $image_save_func = 'imagegif';
                    $new_image_ext = 'gif';
                    break;
    
            default: 
                    throw new Exception('Unknown image type.');
    }
    
    $img = $image_create_func($originalFile);
    list($width, $height) = getimagesize($originalFile);
    
    $newHeight = ($height / $width) * $newWidth;
    $tmp = imagecreatetruecolor($newWidth, $newHeight);
    imagecopyresampled($tmp, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
    
    if (file_exists($targetFile)) {
            unlink($targetFile);
    }
    $image_save_func($tmp, "$targetFile.$new_image_ext");
    

    }

    来源:Resize images with PHP, support PNG, JPG

    【讨论】:

      猜你喜欢
      • 2012-05-01
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2013-01-18
      • 2013-10-29
      • 2016-03-05
      • 2014-11-20
      • 1970-01-01
      相关资源
      最近更新 更多