테스트 사이트 - 개발 중인 베타 버전입니다

코드는 작동되는데 웹페이지 오류가 발생합니다. 채택완료

Sssuj 4년 전 조회 1,474

제가 지금 이미지들과 텍스트를 머지해주는 작업을 하고있는데요, 현재 머지 자체는 정상적으로 진행되어 서버에 저장이 되는데 웹사이트 화면에는 오류가 발생합니다.

 

php 함수 mergeText를 제거하면 결과 이미지가 저장되고 웹사이트도 정상적으로 작동이 되는데 mergeText를 추가하면 결과 이미지는 저장되는데 웹사이트가 정상적으로 작동하지 않습니다.

 

왜 그런걸까요??

결과 이미지와 웹사이트 오류 화면입니다.

 

 

코드입니다.

</strong></p>

<p><!DOCTYPE html>

<html>

<head>

<meta charset="EUC-KR">

    <title>Child</title>

</head>

<body>

<?php

    include_once 'lib/image_proc.function.php';</p>

<p>    $CshowleftImg=$_POST['CshowleftImg'];

    $CshowrightImg=$_POST['CshowrightImg'];

    $CshowbackImg=$_POST['CshowbackImg'];</p>

<p>    $CshowleftImg = str_replace('<a href="https://localhost/'," target="_blank" rel="noopener noreferrer">https://localhost/',</a> '', $CshowleftImg);

    $CshowrightImg = str_replace('<a href="https://localhost/'," target="_blank" rel="noopener noreferrer">https://localhost/',</a> '', $CshowrightImg);

    $CshowbackImg = str_replace('<a href="https://localhost/'," target="_blank" rel="noopener noreferrer">https://localhost/',</a> '', $CshowbackImg);</p>

<p>    //이미지 크기 조절 함수

    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);

    }</p>

<p>    $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'] . "
\n"); 

    resize_image($path_backfile, $path_backfile, 1000, 670);  // 알아서 jpg 유형의 파일 생성</p>

<p>    //왼쪽에 사용될 이미지 리소스를 받아온다.

    list($left, $left_w, $left_h) = get_image_resource_from_file ($path_leftImgk_file);

    if (empty($left)) die($GLOBALS['errormsg'] . "
\n");

    resize_image($path_leftImgk_file, $path_leftImgk_file, 350, 700);  // 알아서 jpg 유형의 파일 생성</p>

<p>

    //오른쪽에 사용될 이미지 리소스를 받아온다.

    list($right, $right_w, $right_h) = get_image_resource_from_file ($path_rightImgk_file);

    if (empty($right)) die($GLOBALS['errormsg'] . "
\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 처리에 실패하였습니다.
\n");</p>

<p>    //배경의 오른쪽 꼭지점을 기준점으로 선명도 100으로

    $result_right = imagecopymerge($back, $right, 600, 180, 0, 0, $right_w, $right_h, 100);

    if ($result_right === false) die("Merge 처리에 실패하였습니다.
\n");</p>

<p>    $result_save = save_image_from_resource ($back, $path_save_file);//저장

    if ($result_save === false) die($GLOBALS['errormsg'] . "
\n");</p>

<p>    @imagedestroy($left);

    @imagedestroy($back);

    @imagedestroy($right);</p>

<p>mergeText($path_save_file);

?></p>

<p><p>Merge 처리한 이미지</p>

<img src='<?= $path_save_file?>'> 
</p>

<p></body>

</html></p>

<p><strong>

댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
    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()호출에 문제가 있는 겁니다.

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

S
Sssuj
4년 전
주석처리 후 실행해도 똑같이 이미지 저장은 잘 돼고 사이트만 오류가 납니다.

댓글을 작성하려면 로그인이 필요합니다.

해피정
4년 전

include 된 lib 파일에 function 으로 mergeText 가 선언된것은 아닌지 확인해보세ㅛ

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

웹솔드
4년 전

</p>

<pre>
<code>$path_save_file = 'mergeImg/mergeImg.jpg';//머지 처리한 것을 저장할 파일</code></pre>

<p><code>

위 경로에 앞에 정확한 url 정보가 없습니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인