2012-02-08 86 views
0

我有一個網站,裏面有一個畫廊,在這個畫廊裏有大拇指,當你點擊它時,你會看到來自linkbucks的廣告。然後當你等待5秒鐘,然後你可以看到它的實際大小的圖片。問題是,用戶只需用鼠標右鍵點擊拇指,然後選擇「顯示圖片」或類似的東西即可跳過此廣告。 如何解決這個問題,而不必爲每張照片製作一個拇指圖像文件?我是否必須爲每張照片創建一個拇指文件?

注:我需要這個解決方案在JavaScript/jquery或/和PHP。

回答

2

除非您製作縮略圖,否則無法阻止它們。如果用戶禁用JavaScript,他們仍然可以下載圖像。 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; 
     } 
    }