PHP图片裁切,左,右
问题描述:
^h家伙,PHP图片裁切,左,右
我UI =唱这段代码上传和裁剪图像。当我把它放在一起原来的作物的中心是在图像的中间,它的工作出色!
我想通过向裁剪选项,而不是裁剪从顶部或左侧或底部居中的图像作物增加的功能性。这将从前一页上的收音机框中选择。
我见过做的一些相当复杂的方式,但不知道是否有实现它的一个简单的方法,有什么想法?谢谢。
$handle->image_resize = true;
$handle->image_ratio_crop = true;
$handle->image_convert = 'jpg';
$handle->image_x = $x;
$handle->image_y = $y;
$handle->jpeg_quality = 75;
$handle->Process($dir_dest);
从形态上页:
<label for="artwork">Banner Artwork</label>
<div class="input-group upload-crop">
<input class="upload-button" accept="image/jpg,image/png,image/jpeg,image/gif" name="<?=$strNameInput?>" id="<?=$strNameInput?>" type="file" />
<label><strong>Crop from:</strong></label>
<label for="centre">Centre</label><input checked type="radio" id="centre" name="crop" value="centre" />
<label for="right">Right</label><input type="radio" id="right" name="crop" value="right" />
<label for="left">Left</label><input type="radio" id="left" name="crop" value="left" />
<label for="top">Top</label><input type="radio" id="top" name="crop" value="top" />
<label for="bottom">Bottom</label><input type="radio" id="bottom" name="crop" value="bottom" />
</div>
答
找到了!我用称为作物(从单选按钮)一个POST变量,如果没有单选按钮被选择它集中作物,如果不是它使用T,B,L或R
$strCrop = $_POST['crop'];
$handle->image_resize = true;
if ($strCrop == '') {
$handle->image_ratio_crop = true;
} else {
$handle->image_ratio_crop = $strCrop;
}
$handle->image_convert = 'jpg';
$handle->image_x = $x;
$handle->image_y = $y;
$handle->jpeg_quality = 75;
$handle->Process($dir_dest);
它使用一个奇特的自举浏览按钮现在:
<div class="btn btn-default btn-file pull-left">
Browse<input class="upload-button" style="display:none" accept="image/jpg,image/png,image/jpeg,image/gif" name="<?=$strNameInput?>" id="<?=$strNameInput?>" type="file" />
</div>
<label><strong>Image crop:</strong></label>
<input checked type="radio" id="centre" name="crop" value="" />
<label for="centre">Centre</label>
<input type="radio" id="right" name="crop" value="R" />
<label for="right">Right</label>
<input type="radio" id="left" name="crop" value="L" />
<label for="left">Left</label>
<input type="radio" id="top" name="crop" value="T" />
<label for="top">Top</label>
<input type="radio" id="bottom" name="crop" value="B" />
<label for="bottom">Bottom</label>