2013-03-12 1 views
1

나는 png 파일을 가지고 있으며이 이미지 (직사각형)의 일부를 투명하게 만들고 싶습니다.PHP : png 파일의 일부를 투명하게 설정하는 방법은 무엇입니까?

같은 것을 forexample :

의사 : X, Y, $ 폭, 높이 $ 투명 설정해야 이미지의 직사각형을 정의

<?php 
$path = 'c:\img.png'; 
set_image_area_transparent($path, $x, $y, $width, $height); 
?> 

.

PHP에서 일부 라이브러리를 사용할 수 있습니까?

답변

1

는 네, 가능합니다. 이미지의 영역을 정의하고 색상으로 채운 다음 해당 색상을 투명 필름으로 설정할 수 있습니다. GD libraries의 가용성이 필요합니다. 각각의 manual for the command이 예에서이 코드를 가지고 : 귀하의 경우에는

<?php 
// Create a 55x30 image 
$im = imagecreatetruecolor(55, 30); 
$red = imagecolorallocate($im, 255, 0, 0); 
$black = imagecolorallocate($im, 0, 0, 0); 

// Make the background transparent 
imagecolortransparent($im, $black); 

// Draw a red rectangle 
imagefilledrectangle($im, 4, 4, 50, 25, $red); 

// Save the image 
imagepng($im, './imagecolortransparent.png'); 
imagedestroy($im); 
?> 

을, 당신은 respective function로 기존 이미지를 취할 것입니다. 위의 예제에서 결과 리소스가 $ im이되면 색상을 할당하고 투명하게 설정하고 위와 같이 사각형을 그린 다음 이미지를 저장 한 다음 이미지를 저장하고 이미지를 저장 한 다음 이미지를 저장 한 다음 이미지를 저장 한 다음 이미지를 저장합니다.

<?php 
// get the image form the filesystem 
$im = imagecreatefromjpeg($imgname); 
// let's assume there is no red in the image, so lets take that one 
$red = imagecolorallocate($im, 255, 0, 0); 

// Make the red color transparent 
imagecolortransparent($im, $red); 

// Draw a red rectangle in the image 
imagefilledrectangle($im, 4, 4, 50, 25, $red); 

// Save the image 
imagepng($im, './imagecolortransparent.png'); 
imagedestroy($im); 
?> 
관련 문제