douzhang8033 2016-05-10 20:47
浏览 25

PHP裁剪图像不符合预期

I'm trying to crop an image using jcrop and a form. When I submit the form all the required data to crop the image, aswell as the image itself, POSTS correctly.

Then I'll upload the original image to the server, and store the filename along with some other data in the database.

After that I start cropping, which does something. But not what I would expect.

I'm trying to crop the following image: enter image description here

As you can see I´m trying to only crop the head off.

When I save the image I´ll get the following as result:

enter image description here

Which as I said is not what I expected.

This is my saving and cropping function:

function file_upload($x1, $y1, $x2, $y2, $w, $h){
            //Bestand opslaan op de server
            $filename = str_replace(' ', '', $_FILES['schilderij_toevoegen_file']['name']);
            $target  = '../Storage/portfolio/'.$filename;
            move_uploaded_file($_FILES['schilderij_toevoegen_file']['tmp_name'], $target);

            //Betand hercroppen
            $copy = imagecreatefromjpeg($target);
            $new = imagecreatetruecolor($w, $h);
            $size = getimagesize($target);
            imagecopyresampled($new, $copy, 0, 0, $x2, $y2, $w, $h, $size[0] * 0.5, $size[1] * 0.5);
            imagejpeg($new, '../Storage/portfolio/crp_'.$filename);

            print 'X1: '.$x1.', Y1: '.$y1.', X2: '.$x2.', Y2: '.$y2.', Width: '.$w.', Height: '.$h;

        }

I'm very new with this cropping function PHP has, so I would appreciate any kind of help.

Edit: These values where used in the function above: X1: 0, Y1: 115, X2: 181, Y2: 299, Width: 181, Height: 184 The original image size is 425x348

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c