H伙计们,
我想用这个代码来上传和裁剪图片。当我把它放在一起时,我最简单地将作物的中心放在图像的中间,它的作品非常出色!
我希望通过添加裁剪选项来增加功能,而不是从顶部或左侧或底部裁剪居中的图像裁剪。这将从上一页的单选框中选择。
我已经看到了一些相当复杂的方法,但想知道是否有一种简单的方法来实现它,任何想法?谢谢。
$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>
答案 0 :(得分:0)
$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>