2012-02-08 3 views
0

나는 갤러리가있는 웹 사이트를 가지고 있는데,이 갤러리에는 엄지 손가락이있어서 클릭하면 linkbucks에서 광고를 볼 수 있습니다. 5 초 동안 기다리면 실제 크기의 그림을 볼 수 있습니다. 문제는 사용자가 마우스 오른쪽 버튼으로 엄지 손가락을 클릭 한 다음 "그림보기"또는 그와 비슷한 것을 선택하여이 광고를 건너 뛸 수 있다는 것입니다. 각 사진에 대해 썸 이미지 파일을 만들 필요없이 어떻게 해결할 수 있습니까?각 그림에 대해 썸 파일을 만들어야합니까?

참고 : Javascript/Jquery 또는/및 PHP를 사용하려면이 솔루션이 필요합니다.

답변

2

미리보기 이미지를 만들지 않으면 절대 멈출 수 없습니다. 사용자가 자바 스크립트를 사용 중지 한 경우 이미지를 계속 다운로드 할 수 있습니다. PHP는 서버 측 언어이기 때문에 이미지를 다운로드 할 수 없으므로 이미지를 브라우저에 전달해야합니다.

3

수 없습니다.

이미 전체 이미지를 제공 한 경우 에는 이미 전체 이미지이 있습니다. 게임 끝.

미리보기 이미지를 만듭니다.

3

실제로 이미지마다 미리보기 이미지를 만들어야한다는 것을 알 수 있습니다. 다른 이미지는 없습니다.

그러나 수동으로 할 필요는 없습니다. PHP는 이미지 파일의 크기를 조정하여 축소판을 동적으로 생성 할 수 있습니다. this one과 같은 자습서를 찾아보십시오.

2

이미지의 미리보기 이미지를 만들어야합니다. 당신은 다음과 같은 간단한 PHP 함수를 사용할 수 있습니다.

/** 
    * Create new thumb images using the source image 
    * 
    * @param string $source - Image source 
    * @param string $destination - Image destination 
    * @param integer $thumbW - Width for the new image 
    * @param integer $thumbH - Height for the new image 
    * @param string $imageType - Type of the image 
    * 
    * @return bool 
    */ 
    function creatThumbImage($source, $destination, $thumbW, $thumbH, $imageType) 
    { 
     list($width, $height, $type, $attr) = getimagesize($source); 
     $x = 0; 
     $y = 0; 
     if ($width*$thumbH>$height*$thumbW) { 
      $x = ceil(($width - $height*$thumbW/$thumbH)/2); 
      $width = $height*$thumbW/$thumbH; 
     } else { 
      $y = ceil(($height - $width*$thumbH/$thumbW)/2); 
      $height = $width*$thumbH/$thumbW; 
     } 

     $newImage = imagecreatetruecolor($thumbW, $thumbH) or die ('Can not use GD'); 

     switch($imageType) { 
      case "image/gif": 
       $image = imagecreatefromgif($source); 
       break; 
      case "image/pjpeg": 
      case "image/jpeg": 
      case "image/jpg": 
       $image = imagecreatefromjpeg($source); 
       break; 
      case "image/png": 
      case "image/x-png": 
       $image = imagecreatefrompng($source); 
       break; 
     } 

     if ([email protected]($newImage, $image, 0, 0, $x, $y, $thumbW, $thumbH, $width, $height)) { 
      return false; 
     } else { 
      imagejpeg($newImage, $destination,100); 
      imagedestroy($image); 
      return true; 
     } 
    } 
관련 문제