dpjo15650 2017-03-21 11:12
浏览 60
已采纳

PHP从url增加图像分辨率然后裁剪

I have images with resolution of 720x1280 and I would need to store them on server with resolution 800x1500. Since 720x1280 increased to height 1500 gives resolution of 844x1500 I would also need to crop image, remove 22 pixels from the left and right side.

For now I have this:

$img_url = file_get_contents($url);

$img = imagecreatefromstring($img_url);

$width = imagesx($img);
$height = imagesy($img);

$new_width = '800';
$new_height = '1500';

$thumb = imagecreatetruecolor($new_width, $new_height);

imagecopyresampled($thumb, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

imagejpeg($thumb, $name, 100);

imagedestroy($thumb);
imagedestroy($img);

But the problem is that image is not cropped, 22 pixels from the left and right side are not removed.

Is there a way to do this, to first increase image resolution from url and then crop?

  • 写回答

2条回答 默认 最新

  • du521521521 2017-03-21 11:57
    关注

    Googling php image crop reveals the secret:

    $rect = [22, 0, 800, 1500]
    $thumb = imagecrop($thumb, $rect)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)