dou7466 2017-01-13 18:19 采纳率: 0%
浏览 31

裁剪图像给出空白图像

Hi I am trying to crop image using codeigniter, jQuery(ui.js). Although the image is being cropped but show black image after cropping. I have made a give called crop_div the div actually has some border and width height. What i am doing is that i am accessing the coordinates of this div using jquery sending them to the php, calling the previous uploaded image and getting the same coordinates from the uploaded image. Here is the code

JS Code

function do_crop(method_url) {
    jQuery('#do_crop').on('submit', (function(e) {
        e.preventDefault();
        var posi = document.getElementById('crop_div');
        var top = document.getElementById("top").value=posi.offsetTop;
        var left = document.getElementById("left").value=posi.offsetLeft;
        var right = document.getElementById("right").value=posi.offsetWidth;
        var bottom = document.getElementById("bottom").value=posi.offsetHeight;
        jQuery.ajax({
            url: method_url,
            type: 'POST',
            data: { 'top': top, 'left': left, 'bottom': bottom, 'right': right },
            success: function(data) {
                jQuery('.result').show();
                if(data == 'Profile uploaded.') {
                    window.location.href = reload;
                    jQuery('#PicprofileBtn').html('Submit');
                }
                else {
                    alert(data);
                }
            }
        });
    }));
}

PHP Code

        public function do_crop() {

        $y1 = $this -> input -> post('top');
        $x1 = $this -> input -> post('left');
        $w = $this -> input -> post('right');
        $h = $this -> input -> post('bottom');

        $image = "Users_Data/profile/8ca760ccc0bf60566fdd4ccc2cd213e8.jpg";

        list($width,$height ) = getimagesize( $image );
        $newwidth = 600;
        $newheight = 400;

        $thumb = imagecreatetruecolor( $newwidth, $newheight );
        $source = imagecreatefromjpeg($image);

        imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        imagejpeg($thumb,$image,100); 


        $im = imagecreatefromjpeg($image);
        $dest = imagecreatetruecolor($w,$h);

        imagecopyresampled($dest,$im,0,0,$x1,$y1,$w,$h,$w,$h);
        imagejpeg($dest,"Users_Data/thumb/crop_image.jpg", 100);

    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号