PHP를 사용하여 이미지 위에 텍스트를 쓰고 있습니다. 현재 이미지에서 새 이미지를 쉽게 작성하고 PHP를 사용하여 텍스트를 쓰고 있습니다.하지만 변경 사항 적용을 클릭하면이 새 이미지를 내 디렉토리 (move_uploaded_file)로 옮길 수도 있습니다. 현재 이미지를 새 이미지로 바꾸고 새 이미지 이름은 PHP를 사용하여 다운로드하기 때문에 이전 이미지와 동일해야합니다.@imagecreatefromjpeg의 <img> 태그를 받으시겠습니까?
여기에 텍스트를 쓰는 데 사용하는 코드가 있습니다.
HTML 코드 :
<img id="image" src="<?php echo "upload_pic/" . $_FILES["image_file"]["name"]; ?>" alt="your_image" />
<input type="button" name="save_image" id="save_image" value="Save Image" />
<input type="hidden" id="hidden_image_name" name="hidden_image_name" value="<?php echo $_FILES["image_file"]["name"]; ?>" />
jQuery를 코드 : 고급의
jQuery('#save_image').click(function(){
var image_name = jQuery('#hidden_image_name').val();
jQuery.ajax({
url:'text_image.php',
data:'file='+image_name,
type:'get',
success:function(data){
alert(data);
}
});
});
text_image.php
<?php
$file = 'upload_pic/'.$_GET['file'];
/*** set the header for the image ***/
header("Content-type: image/jpeg");
/*** specify an image and text ***/
$im = writeToImage($file, 'PHPRO rules again');
//echo $im;
/*** spit the image out the other end ***/
imagejpeg($im);
/**
*
* @Write text to an existing image
*
* @Author Kevin Waterson
*
* @access public
*
* @param string The image path
*
* @param string The text string
*
* @return resource
*
*/
function writeToImage($imagefile, $text){
/*** make sure the file exists ***/
if(file_exists($imagefile))
{
/*** create image ***/
$im = @imagecreatefromjpeg($imagefile);
/*** create the text color ***/
$text_color = imagecolorallocate($im, 233, 14, 91);
/*** splatter the image with text ***/
imagestring($im, 6, 25, 150, "$text", $text_color);
}
else
{
/*** if the file does not exist we will create our own image ***/
/*** Create a black image ***/
$im = imagecreatetruecolor(150, 30); /* Create a black image */
/*** the background color ***/
$bgc = imagecolorallocate($im, 255, 255, 255);
/*** the text color ***/
$tc = imagecolorallocate($im, 0, 0, 0);
/*** a little rectangle ***/
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/*** output and error message ***/
imagestring($im, 1, 5, 5, "Error loading $imagefile", $tc);
}
return $im;
}
?>
감사합니다!
응답이 매우 복잡합니다. JFIF > 제작자 : gd-jpeg v1.0 (IJG JPEG v62 사용), 기본 품질 C \t \t $. ' "# (7) 01444'9 = 82 <.342C \t \t \t 2 22222222222222222222222222222222222222222222222222 !!"\t ! 1AQa "q2 # B R $ 3br – CuteBabyMannu
"복잡하지 "않은 문자는 텍스트 모드로 볼 때 jpeg 이미지가 나타나는 모양입니다. – Spudley
또한'$ _FILES [ "image_file"] [ "name"]'을 사용하면주의를 기울이십시오 - 파일의'name '은 클라이언트에 의해 결정되므로 공격 벡터로 사용할 수 있습니다. 슬래시가 포함되어 있으면 코드가 예상 한 것과 다른 파일을로드 할 수 있습니다. 사용하기 전에 위생 처리를했는지 또는 전혀 사용하지 않아야합니다 (즉, 업로드 한 파일의 고유 한 이름을 만드십시오). – Spudley