2012-06-14 69 views
0

我使用的是數字水印系統,以保護我所有的照片我的網頁上:谷歌瀏覽器「無法加載資源」

<?php 
$imagesource = $_SERVER['DOCUMENT_ROOT']."**path**".$_GET['path']; 
if (!file_exists($imagesource)) die(); 
$filetype = strtolower(substr($imagesource,strlen($imagesource)-4,4)); 
if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); 
if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); 
if($filetype == ".png") $image = @imagecreatefrompng($imagesource); 
if (empty($image)) die(); 
$watermark = @imagecreatefrompng('watermark_'.(imagesx($image) <= 1100 ? "port" : "lans").'.png'); 
$imagewidth = imagesx($image); 
$imageheight = imagesy($image); 
$watermarkwidth = imagesx($watermark); 
$watermarkheight = imagesy($watermark); 
$startwidth = (($imagewidth - $watermarkwidth)/2); 
$startheight = (($imageheight - $watermarkheight)/2); 
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); 
header("Content-type: image/jpeg"); 
imagejpeg($image); 
imagedestroy($image); 
imagedestroy($watermark); 
?> 

這工作得很好,但是當我加載該頁面在谷歌瀏覽器的圖像預加載和顯示,但只要他們呈現Chrome說「無法加載資源」。這很奇怪,因爲如果你沒有加載它,爲什麼你顯示它呢?

無論如何,我不能在任何其他瀏覽器上覆制此問題。這又奇怪了,這告訴我腳本沒有錯。

我一直注意到圖像越小,我的顯示屏就越正確,但是有什麼好處是19幅圖像中的2幅正在加載!

現在,當我正常顯示圖像,這不會發生(即不帶水印的腳本。通過「<‘IMG’> <‘/ IMG’>」標籤)

但在其他網站上我有沒有加水印腳本,但他們仍然沒有加載。

我的另一個問題是,

由於管理我的網站合同的法律,我必須對原始文件使用版權和.htaccess保護......無論如何,用戶無法直接訪問圖像源文件。這些錯誤可能是由此造成的嗎?但是爲什麼有些顯示器和其他顯示器不顯示,並且同樣地,爲什麼只有谷歌瀏覽器纔會出現這個問題?

您的想法將被appriciated。

P.S.這是我的瀏覽器信息:

Google Chrome 19.0.1084.56 (Official Build 140965) m 
OS Windows 
WebKit 536.5 (@119244) 
JavaScript V8 3.9.24.29 
Flash 11,3,300,257 
User Agent Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5 

視覺舉例:

Loading

Loaded

回答

1

似乎是在瀏覽器的錯誤。一直讓我瘋狂的人結束了使用base64的「修復」。讓您的水印腳本完全一樣,並進入輸出圖像的腳本。

function base64_encode_image ($imagefile) { 
     $filename=htmlentities($imagefile); 
     $filetype = pathinfo($filename, PATHINFO_EXTENSION); 
     $imgbinary = file_get_contents($filename); 
     return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary); 
} 

$string=base64_encode_image("http://www.domain.com.au/watermark.php?imagesrc=image1.jpg"); 

$imgList.="<img src=\"$string\" title=\"\">"; 
0

可能是問題的原因,因爲您不回饋Content-Lentgh。

你必須用下面的代碼替換線imagejpeg($image);

imagejpeg($image, 'php://memory/temp.jpeg'); 
    header("Content-Length: " . filesize('php://memory/temp.jpeg')); 
    $fp = fopen("php://temp/temp.jpeg", 'r'); 
    echo stream_get_contents($fp); 
相關問題