Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

PHP – ดึง Clipping Rectangle ด้วย imagegetclip()

ฟังก์ชัน imagegetclip() ใช้ดึง clipping rectangle ปัจจุบัน คือพื้นที่ที่อนุญาตให้วาด pixel ได้ พื้นที่นอกเหนือจากนี้จะไม่มีการวาด

รูปแบบการใช้งาน (Syntax)

array imagegetclip(GdImage $image)

พารามิเตอร์

  • $image – GdImage resource จาก imagecreatetruecolor() หรือฟังก์ชันสร้างภาพอื่นๆ

ค่าที่คืนกลับ

คืน indexed array พิกัด clipping rectangle: [x1, y1, x2, y2] (มุมซ้ายบน และ มุมขวาล่าง)

ตัวอย่าง 1: ตั้งค่า clip แล้วดึงค่า

<?php
$img = imagecreate(200, 200);
imagesetclip($img, 20, 20, 90, 90);
print_r(imagegetclip($img));
?>

ผลลัพธ์

Array ( [0] => 20 [1] => 20 [2] => 90 [3] => 90 )

ตัวอย่าง 2: ดึง clip ของรูปภาพที่โหลดมา

<?php
$img = imagecreatefrompng('C:\xampp\htdocs\Images\img34.png');
print("
" . print_r(imagegetclip($img), true) . "
"); ?>

ผลลัพธ์

Array ( [0] => 0 [1] => 0 [2] => 611 [3] => 395 )