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

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条)

报告相同问题?

悬赏问题

  • ¥15 使用MATLAB进行余弦相似度计算加速
  • ¥15 服务器安装php5.6版本
  • ¥15 我想用51单片机和数码管做一个从0开始的计数表 我写了一串代码 但是放到单片机里面数码管只闪烁一下然后熄灭
  • ¥20 系统工程中,状态空间模型中状态方程的应用。请猛男来完整讲一下下面所有问题
  • ¥15 我想在WPF的Model Code中获取ViewModel Code中的一个参数
  • ¥15 arcgis处理土地利用道路 建筑 林地分类
  • ¥20 使用visual studio 工具用C++语音,调用openslsx库读取excel文件的sheet问题
  • ¥100 寻会做云闪付tn转h5支付链接的技术
  • ¥15 DockerSwarm跨节点无法访问问题
  • ¥15 使用dify通过OpenAI 的API keys添加OpenAI模型时报了“Connection Error”错误