【问题标题】:imagecopy - cropping image instead of resizingimagecopy - 裁剪图像而不是调整大小
【发布时间】:2014-12-15 01:53:37
【问题描述】:

我想调整大小 - $artfile,并从 $start_x, $start_y 开始将 store 放到 $dest

$dest 包含一个框架。 $artfile 需要适合框架,所以我需要调整它的大小。

我的代码是:

imagecopy($dest, $art_file, $start_x, $start_y, 0, 0, $new_width, $new_height); // works fine but to test resize

$dest = my destination resource
$artfile = resource that I want to patch with $destination
$new_width, $new_height = I want $art_file to be resized to this value, without trimming off or cropping. 

我的问题是:

对于尺寸超过$new_height$new_width 的任何图像,将剪掉更多。我想将整个集合调整为$new_height$new_width

有什么帮助吗?

【问题讨论】:

    标签: php html gd


    【解决方案1】:

    玩这个,希望对你有所帮助;

     <?php
     Function createthumbnail($src=null,$newHeight=null) {
        $srcimg = imagecreatefromjpeg($src);
        $srcsize = getimagesize($src);
        $dest_y = $newHeight;
        $dest_x = ($newHeight / $srcsize[1]) * $srcsize[0];
        $thumbimg = imagecreatetruecolor($dest_x, $dest_y);
        imagecopyresampled($thumbimg,$srcimg,0,0,0,0,$dest_x,$dest_y, $srcsize[0], $srcsize[1]);
        $thumbimg = imagejpeg($thumbimg,$src);
        return $thumbimg;
    }
    ?>
    

    你可以这样称呼它

    <?php
    resizedImage = createthumbnail(urlOfFileToResize,newHeight);//newHeight would be like 1 or 50 or 1000......
    ?>
    

    现在您调整大小的图像将存储在 resizedImage 中

    不客气。

    【讨论】:

      猜你喜欢
      • 2017-02-02
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 2013-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多