我有一个网站,其中有一个图库,在这个图库中有拇指,点击后会带你到来自linkbucks的广告。然后,等待5秒后,您可以看到实际尺寸的图片。问题是,用户只需用鼠标右键单击拇指即可跳过此广告,然后选择“显示图片”或类似内容。 如何解决这个问题而不必为每张图片制作一个拇指图像文件?
注意:我需要将此解决方案放在Javascript / Jquery或/和PHP中。
答案 0 :(得分:3)
你不能。
如果您已经为他们提供了完整的图片,他们已经拥有完整的图片。游戏结束。
制作缩略图。
答案 1 :(得分:3)
你可以看到你确实需要为每个图像创建一个缩略图,这里别无选择。
但是,您不必手动执行此操作:PHP能够调整图像文件的大小,从而动态生成缩略图。寻找教程,例如this one。
答案 2 :(得分:2)
除非您制作缩略图,否则永远不能阻止它们。如果用户禁用了javascript,他们仍然可以下载图片。 PHP无法阻止他们下载图像,因为它是服务器端语言,必须将图像传送到浏览器。
答案 3 :(得分: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 (!@imagecopyresampled($newImage, $image, 0, 0, $x, $y, $thumbW, $thumbH, $width, $height)) {
return false;
} else {
imagejpeg($newImage, $destination,100);
imagedestroy($image);
return true;
}
}