如何在 PHP 中使用 imageinterlace() 函式啟用或停用隔行掃描?


imageinterlace() 是一個內建的 PHP 函式,用於啟用或停用影像的隔行掃描。它是一種編碼點陣圖影像的方法,這樣即使使用者只接收了部分影像,也能看到整個影像的降級副本。

隔行掃描影像允許使用者在影像載入時看到部分內容,並且根據影像型別採用不同的形式。非隔行掃描的 JPEG 影像逐行顯示。要為圖片啟用隔行掃描,我們可以簡單地呼叫此函式並將第二個引數設定為 1,或者設定為 0(零)以停用它。

語法

int imageinterlace(resource $image, int $interlace)

引數

imageinterlace() 接受兩個引數:$image$interlace

  • $image − 指定要進行隔行掃描的影像。

  • $interlace − 指定是否啟用或停用隔行掃描。

返回值

如果為影像設定了隔行掃描位,則 imageinterlace() 返回 1,否則返回 0。

示例 1

<?php
   //load an image by using imagecreatefromjpeg() function
   $img = imagecreatefromjpeg('C:\xampp\htdocs\test\30.jpg');
   // Enable interlacing by using one
   imageinterlace($img, 1);

   // View the output image
   header('Content-type: image/jpeg');
   imagejpeg($img);
   imagedestroy($img);
?>


示例 2

在這個例子中,我們停用了隔行掃描。

<?php
   //load an image by using imagecreatefromjpeg() function
   $img = imagecreatefromjpeg('C:\xampp\htdocs\test\30.jpg');

   // Disable interlacing by using zero
   imageinterlace($img, 0);

   // View the output image
   header('Content-type: image/jpeg');
   imagejpeg($img);
   imagedestroy($img);
?>

輸出

更新於: 2021-08-09

434 次檢視

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告