我有一个网站,里面有一个画廊,在这个画廊里有大拇指,当你点击它时,你会看到来自linkbucks的广告。然后当你等待5秒钟,然后你可以看到它的实际大小的图片。问题是,用户只需用鼠标右键点击拇指,然后选择“显示图片”或类似的东西即可跳过此广告。 如何解决这个问题,而不必为每张照片制作一个拇指图像文件?我是否必须为每张照片创建一个拇指文件?
注:我需要这个解决方案在JavaScript/jquery或/和PHP。
我有一个网站,里面有一个画廊,在这个画廊里有大拇指,当你点击它时,你会看到来自linkbucks的广告。然后当你等待5秒钟,然后你可以看到它的实际大小的图片。问题是,用户只需用鼠标右键点击拇指,然后选择“显示图片”或类似的东西即可跳过此广告。 如何解决这个问题,而不必为每张照片制作一个拇指图像文件?我是否必须为每张照片创建一个拇指文件?
注:我需要这个解决方案在JavaScript/jquery或/和PHP。
除非您制作缩略图,否则无法阻止它们。如果用户禁用JavaScript,他们仍然可以下载图像。 PHP无法阻止他们下载图像,因为它是服务器端语言,必须将图像传送到浏览器。
你不能。
如果您已经为他们提供完整图像,他们已经有完整图像。游戏结束。
制作缩略图。
你可以看到你实际上需要为每个图像创建一个缩略图,这里没有别的办法。
但是,您不必手动执行:PHP可以调整图像文件的大小,从而动态生成缩略图。寻找教程,如this one。
您必须为图像创建缩略图。您可以使用简单的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;
}
}