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

ฟังก์ชัน imagecopy() ใน PHP


ฟังก์ชัน imagecopy() คัดลอกส่วนของภาพจาก source ไป destination

ไวยากรณ์

imagecopy(dst_img, src_img, dst_x, dst_y, src_x, src_y, src_w, src_h)

พารามิเตอร์

  • dst_img: Destination image resource
  • src_img: Source image resource
  • dst_x: X ของ destination
  • dst_y: Y ของ destination
  • src_x: X ของ source
  • src_y: Y ของ source
  • src_w: ความกว้างของ source
  • src_h: ความสูงของ source

คืนค่า

TRUE ถ้าสำเร็จ FALSE ถ้าล้มเหลว

ตัวอย่าง

<?php 
$srcImg = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif'); 
$dest = imagecreatetruecolor(170, 140); 
imagecopy($dest, $srcImg, 0, 0, 0, 0, 180, 260); 
header('Content-Type: image/gif'); 
imagegif($dest); 
imagedestroy($dest); 
imagedestroy($srcImg); 
?>

ผลลัพธ์

ฟังก์ชัน imagecopy() ใน PHP

ตัวอย่างที่ 2

<?php 
$srcImg = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif'); 
$dest = imagecreatetruecolor(170, 140); 
imagecopy($dest, $srcImg, 10, 20, 0, 0, 100, 280); 
header('Content-Type: image/gif'); 
imagegif($dest); 
imagedestroy($dest); 
imagedestroy($srcImg); 
?>

ผลลัพธ์

ฟังก์ชัน imagecopy() ใน PHP