ฉันกำลังพยายามลดขนาดรูปภาพโปร่งใสบางส่วนใน PHP ด้วย GD และทุกครั้งที่ฉันทำ ก็จะมีเส้นขอบสีดำแปลกๆ เพิ่มเข้ามารอบๆ รูปภาพ
ก่อน
หลัง
รหัส
<?php
$image = imagecreatefromstring(file_get_contents('logo.png'));
$width = imagesx($image);
$height = imagesy($image);
$newWidth = $width - 1;
$newHeight = $height - 1;
$output = imagecreatetruecolor($newWidth, $newHeight);
imagecolortransparent($output, imagecolorallocatealpha($output, 0, 0, 0, 127));
imagealphablending($output, false);
imagesavealpha($output, true);
imagecopyresampled($output, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
header('Content-Type: image/png');
imagepng($output);
?>
ดูเหมือนว่าถ้าฉันเปลี่ยนโค้ดสำหรับมิติใหม่ให้เหมือนกับอันเก่า (ลบ - 1
ออก) จะไม่มีเส้นขอบสีดำปรากฏขึ้น ดังนั้นการปรับขนาดจึงทำให้เกิดปัญหา
ไม่มีใครมีความคิดว่าสิ่งที่อาจจะผิด?
แก้ไข: ฉันเพิ่งรู้ว่ามันเกิดขึ้นกับ imagecopyresampled
เท่านั้น และไม่ใช่ imagecopyresized
อย่างไรก็ตาม imagecopyresampled
ให้เอฟเฟ็กต์ภาพที่ดีกว่ามากและฉันต้องการทำให้มันใช้งานได้ถ้าเป็นไปได้
imagecopyresampled
เท่านั้น ไม่ใช่imagecopyresized
. อย่างไรก็ตามimagecopyresampled
ให้เอฟเฟ็กต์ภาพที่ดีกว่ามากและฉันต้องการทำให้มันใช้งานได้ถ้าเป็นไปได้ - person Alex Turpin   schedule 15.11.2011