gd함수로 링크 생성후 링크접속 문의드립니다.
조회수 5936 답변수 1 반응수 2 등록일 2016.05.23 13:35:34

일단 구현하려는 코드는, gd 라이브러리로 링크 이미지를 생성후,

html 코드

<img src="linkimage.php" />

-----------------------------

php 코드

<?php
if(isset($_SERVER['HTTP_REFERER'])) {
 header("Content-type: image/png");
// header('Location: http://www.example.com/');
 // Set some important CAPTCHA constants
 define('CAPTCHA_NUMCHARS', 6); // number of characters in pass-phrase
 define('CAPTCHA_WIDTH', 200); // width of image
 define('CAPTCHA_HEIGHT', 16); // height of image

// $link = $_GET['link'];

$link = "http://www.example.com/";
 // Create the image
 $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT);

// Set a white background with black text and gray graphics
 $bg_color = imagecolorallocate($img, 255, 255, 255); // white
 $text_color = imagecolorallocate($img, 0, 0, 204); // blue

// Fill the background
 imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color);


 // Draw the pass-phrase string
 imagettftext($img, 10, 0, 0, CAPTCHA_HEIGHT - 5, $text_color, 'gulim.ttc', $link);

// Output the image as a PNG using a header

imagepng($img);

// Clean up
 imagedestroy($img);
}
else{
 header('Location: http://www.example.com/');
}
?>

이미지를 클릭시 링크로 연결되는 소스인데요..

리퍼러를 전달하여 처리하려는데 제가 잘못짚은거같네요..

고수분들 도움좀 부탁드립니다.

이미지가 안그려지는 건가요 링크로 연결이 안된다는 건가요? php freetype 은 컴파일 되어 있는 거겟쬬.? 에러로그 활성화 시켜 주신담에 로그좀 찍어 작성해 주시면 도움이 될거 같아요~ John.cho 2016.05.23 14:19:01
  1. <?php
  2. header("Content-type: image/png");
  3. define('CAPTCHA_NUMCHARS', 6); // number of characters in pass-phrase
  4. define('CAPTCHA_WIDTH', 200); // width of image
  5. define('CAPTCHA_HEIGHT', 16); // height of image
  6. $link = "http://www.example.com/";
  7. $img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT);
  8. $bg_color = imagecolorallocate($img, 255, 255, 255); // white
  9. $text_color = imagecolorallocate($img, 0, 0, 204); // blue
  10. imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bg_color);
  11. imagettftext($img, 10, 0, 0, CAPTCHA_HEIGHT - 5, $text_color, 'gulim.ttf', $link);
  12. imagepng($img);
  13. imagedestroy($img);
  14. ?>
  1. PHP Warning: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Could not find/open font in 

위가 에러 메세지네..

font 파일을 찾거나 오픈할 수 없다고 합니다.

imagettftext 함수 중 'gulim.ttc'    ->      'gulim.ttf'   로 수정해보세요

오타인듯 합니다.

2016.05.23 20:58:10 반응 이력

답변 작성

질문에 적합한 답변을 상세히 작성해 주시기 바랍니다.

답변이 찬성되면 태그평판 +2점이 적립, 반대되면 태그평판 -1점 차감됩니다.

답변이 채택되면 태그평판 +10점이 적립됩니다.

PHP 게시판 정보
  • 34
    질문수
  • 9
    아카이브수
  • 28
    채택수
  • 2
    멤버수
PHP 질문 통계
최근 30일
답변율
0%
채택율
0%
전체
답변율
85%
채택율
82%
최근에 등록된 질문