首页 > 解决方案 > 将图像分成两部分并显示图像 PHP

问题描述

我希望将图像分成两部分并保存图像并返回图像 url。我已经编写了代码,但不幸的是它无法正常工作,如果您知道解决方案,请告诉我

$orig = site_url('/') . $_POST['BatImageUrl'];

$width = 2500;
$height = 300;

if( $_POST['partName'] == 'handle' ) {

    $leftSide = imagecreatetruecolor($width/2, $height);

    $handleimage = imagecreatefrompng("handle-image.png"); 

    imagecopy($leftSide, $orig, 0, 0, 0, 0, $width/2, $height);

    header('Content-Type: image/gif');
    imagepng($leftSide, $handleimage);

    imagedestroy($leftSide);

} else {

    $rightSide = imagecreatetruecolor($width/2, $height);

    $barrelimage = imagecreatefrompng("barrel-image.png"); 

    imagecopy($rightSide, $orig, 0, 0, $width/2, 0, $width/2, $height);

    header('Content-Type: image/gif');
    imagepng($rightSide, $barrelimage);

    imagedestroy($rightSide);

}

imagedestroy($orig);

标签: phpjqueryajax

解决方案


推荐阅读