코드는 작동되는데 웹페이지 오류가 발생합니다.
본문
제가 지금 이미지들과 텍스트를 머지해주는 작업을 하고있는데요, 현재 머지 자체는 정상적으로 진행되어 서버에 저장이 되는데 웹사이트 화면에는 오류가 발생합니다.
php 함수 mergeText를 제거하면 결과 이미지가 저장되고 웹사이트도 정상적으로 작동이 되는데 mergeText를 추가하면 결과 이미지는 저장되는데 웹사이트가 정상적으로 작동하지 않습니다.
왜 그런걸까요??
코드입니다.
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Child</title>
</head>
<body>
<?php
include_once 'lib/image_proc.function.php';
$CshowleftImg=$_POST['CshowleftImg'];
$CshowrightImg=$_POST['CshowrightImg'];
$CshowbackImg=$_POST['CshowbackImg'];
$CshowleftImg = str_replace('https://localhost/', '', $CshowleftImg);
$CshowrightImg = str_replace('https://localhost/', '', $CshowrightImg);
$CshowbackImg = str_replace('https://localhost/', '', $CshowbackImg);
//이미지 크기 조절 함수
function resize_image($file, $newfile, $w, $h) {
list($width, $height) = getimagesize($file);
if(strpos(strtolower($file), ".jpg"))
$src = imagecreatefromjpeg($file);
else if(strpos(strtolower($file), ".png"))
$src = imagecreatefrompng($file);
else if(strpos(strtolower($file), ".gif"))
$src = imagecreatefromgif($file);
$dst = imagecreatetruecolor($w, $h);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height);
if(strpos(strtolower($newfile), ".jpg"))
imagejpeg($dst, $newfile);
else if(strpos(strtolower($newfile), ".png"))
imagepng($dst, $newfile);
else if(strpos(strtolower($newfile), ".gif"))
imagegif($dst, $newfile);
}
function mergeText($path_save_file){
$im = imagecreatefromjpeg($path_save_file);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$font_file = './Daum_Regular.ttf';
imagefttext($im, 80, 0, 200, 600, $black, $font_file, '000 vs 000');
header('Content-Type: image/jpeg');
imagejpeg($im, $path_save_file);
imagedestroy($im);
}
$path_backfile = $CshowbackImg;//배경
$path_leftImgk_file = $CshowleftImg;//왼쪽
$path_rightImgk_file = $CshowrightImg;//오른쪽
$path_save_file = 'mergeImg/mergeImg.jpg';//머지 처리한 것을 저장할 파일
//배경의 이미지 리소스를 받아온다.
list($back, $back_w, $back_h) = get_image_resource_from_file ($path_backfile);
if (empty($back)) die($GLOBALS['errormsg'] . "<br />\n");
resize_image($path_backfile, $path_backfile, 1000, 670); // 알아서 jpg 유형의 파일 생성
//왼쪽에 사용될 이미지 리소스를 받아온다.
list($left, $left_w, $left_h) = get_image_resource_from_file ($path_leftImgk_file);
if (empty($left)) die($GLOBALS['errormsg'] . "<br />\n");
resize_image($path_leftImgk_file, $path_leftImgk_file, 350, 700); // 알아서 jpg 유형의 파일 생성
//오른쪽에 사용될 이미지 리소스를 받아온다.
list($right, $right_w, $right_h) = get_image_resource_from_file ($path_rightImgk_file);
if (empty($right)) die($GLOBALS['errormsg'] . "<br />\n");
resize_image($path_rightImgk_file, $path_rightImgk_file, 350, 700); // 알아서 jpg 유형의 파일 생성
//배경의 왼쪽 꼭지점을 기준점으로 선명도 100으로
$result_left = imagecopymerge($back, $left, 50, 180, 0, 0, $left_w, $left_h, 100);
if ($result_left === false) die("Merge 처리에 실패하였습니다.<br />\n");
//배경의 오른쪽 꼭지점을 기준점으로 선명도 100으로
$result_right = imagecopymerge($back, $right, 600, 180, 0, 0, $right_w, $right_h, 100);
if ($result_right === false) die("Merge 처리에 실패하였습니다.<br />\n");
$result_save = save_image_from_resource ($back, $path_save_file);//저장
if ($result_save === false) die($GLOBALS['errormsg'] . "<br />\n");
@imagedestroy($left);
@imagedestroy($back);
@imagedestroy($right);
mergeText($path_save_file);
?>
<p>Merge 처리한 이미지</p>
<img src='<?= $path_save_file?>'> <br />
</body>
</html>
답변 3
function mergeText($path_save_file){
$im = imagecreatefromjpeg($path_save_file);
$black = imagecolorallocate($im, 0x00, 0x00, 0x00);
$font_file = './Daum_Regular.ttf';
// imagefttext($im, 80, 0, 200, 600, $black, $font_file, '000 vs 000');
header('Content-Type: image/jpeg');
imagejpeg($im, $path_save_file);
imagedestroy($im);
}
이렇게 해서 이미지가 나오는지 확인해 보세요. 그렇다면 imagefttext()호출에 문제가 있는 겁니다.
$path_save_file = 'mergeImg/mergeImg.jpg';//머지 처리한 것을 저장할 파일
위 경로에 앞에 정확한 url 정보가 없습니다.
include 된 lib 파일에 function 으로 mergeText 가 선언된것은 아닌지 확인해보세ㅛ
답변을 작성하시기 전에 로그인 해주세요.