imageconvolution() เป็นฟังก์ชัน inbuilt ใน PHP ที่ใช้เพื่อใช้เมทริกซ์การบิดแบบ 3×3 โดยใช้ค่าสัมประสิทธิ์และออฟเซ็ตในรูปภาพ
ไวยากรณ์
bool imageconvolution ( $image, $matrix, $div, $offset)
พารามิเตอร์
imageconvolution() ใช้พารามิเตอร์สี่ตัว:$image, $matrix, $div และ $offset
-
$image − พารามิเตอร์นี้ใช้เพื่อสร้างขนาดของรูปภาพโดยใช้ฟังก์ชันการสร้างรูปภาพ เช่น imagecreatetruecolor()
-
$เมทริกซ์ − พารามิเตอร์นี้มีอาร์เรย์ของเมทริกซ์ลอยตัว 3×3
-
$div − ใช้สำหรับการทำให้เป็นมาตรฐาน
-
$offset − พารามิเตอร์นี้ใช้เพื่อตั้งค่าการชดเชยสี
คืนค่า
imageconvolution() คืนค่า True เมื่อสำเร็จและ False เมื่อล้มเหลว
ตัวอย่างที่ 1
<?php
// load the PNG image by using imagecreatefrompng function.
$image = imagecreatefrompng('C:\xampp\htdocs\Images\img59.png');
// Applied the 3X3 array matrix
$matrix = array(
array(2, 0, 0),
array(0, -1, 0),
array(0, 0, -1)
);
// imageconvolution function to modify image elements
imageconvolution($image, $matrix, 1, 127);
// show the output image in the browser
header('Content-Type: image/png');
imagepng($image, null, 9);
?> ผลลัพธ์
ป้อนรูปภาพ PNG ก่อนใช้ฟังก์ชัน imageconvolution()

ส่งออกรูปภาพ PNG หลังจากใช้ฟังก์ชัน imageconvolution()

ตัวอย่างที่ 2
<?php
$image = imagecreatetruecolor(700, 300);
// Writes the text and apply a gaussian blur on the image
imagestring($image, 50, 25, 8, 'Gaussian Blur Text image', 0x00ff00);
$gaussian = array(
array(1.0, 2.0, 1.0),
array(2.0, 4.0, 2.0),
array(1.0, 2.0, 1.0)
);
imageconvolution($image, $gaussian, 16, 0);
// Rewrites the text for comparison
imagestring($image, 15, 20, 18, 'Gaussian Blur Text image', 0x00ff00);
header('Content-Type: image/png');
imagepng($image, null, 9);
?> ผลลัพธ์
