簡體   English   中英

在PHP imagecopy中裁剪圖像重新采樣-壓縮而不是裁剪

[英]Cropping image in PHP imagecopyresampled - squashing instead of cropping

我正在使用jCrop裁剪圖像。 這段代碼之前在另一個頁面上工作,但是當我在另一個頁面上實現它時似乎正在播放。

當我運行此代碼時,代碼會先顯示原始圖像,然后將其壓縮,然后將整個圖像放入要裁剪的盒子中。

這些值將從$ _POST值中的jCrop正確返回。

$origURL=$_POST['CelebrityPicURL'];
$x = $_POST['x'];
$y = $_POST['y'];
$w = $_POST['w'];
$h = $_POST['h'];

$targ_w = $targ_h = 300;
$jpeg_quality = 90;

$img_r = imagecreatefromjpeg($origURL);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);


imagejpeg($dst_r,$origURL,$jpeg_quality);

您可以簡單地使用imagecopy() 就像是...

$dst_r = imagecreatetruecolor((int) $w, (int) $h);
imagecopy($dst_r, $img_r, 0, 0, (int) $x, (int) $y, (int) $w, (int) $h);

當然,您還需要檢查超出范圍的條件並適當地處理它們。 不知道為什么要從$_POST數組中獲取數據來設置和/或使用$targ_w$targ_h

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM