imageconvolution() áp dụng ma trận tích chập (convolution matrix 3x3) lên hình ảnh, dùng cho làm mờ, tăng cường cạnh, emboss...
Cú pháp
imageconvolution(resource $image, array $matrix, float $div, float $offset): bool
Tham số
- image: Resource từ
imagecreatetruecolor()hoặcimagecreatefrom*. - matrix: Mảng 3x3 (3 mảng con, mỗi mảng 3 float).
- div: Mẫu số chuẩn hóa kết quả.
- offset: Độ bù màu (color offset).
Ví dụ
<?php
$img = imagecreatefromgif('https://example.com/image.gif');
$matrix = [
[2, 0, 1],
[-1, -1, 0],
[0, 0, -1]
];
imageconvolution($img, $matrix, 1, 127);
header('Content-Type: image/png');
imagepng($img, null, 9);
?>
Thay đổi matrix, div, offset tạo hiệu ứng khác nhau (sharpen, blur, edge detect...).