我有一個關於圖像顯示使用函數getImage_w($ image,$ dst_w),它需要圖像的URL($ image)和這個圖像的目的地寬度($大小)..然後它重新繪製圖像改變其高度根據目的地的寬度。圖像顯示使用PHP而不影響HTML代碼
是這樣的函數(在庫/ image.php文件):
function getImage_w($image,$w){
/*** get The extension of the image****/
$ext= strrchr($image, ".");
/***check if the extesion is a jpeg***/
if (strtolower($ext)=='.jpg' || strtolower($ext)=='.jpeg'){
/***send the headers****/
header('Content-type: image/jpeg');
/**get the source image***/
$src_im_jpg=imagecreatefromjpeg($image);
/****get the source image size***/
$size=getimagesize($image);
$src_w=$size[0];
$src_h=$size[1];
/****calculate the distination height based on the destination width****/
$dst_w=$w;
$dst_h=round(($dst_w/$src_w)*$src_h);
$dst_im=imagecreatetruecolor($dst_w,$dst_h);
/**** create a jpeg image with the new dimensions***/
imagecopyresampled($dst_im,$src_im_jpg,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
imagejpeg($dst_im);
}
在文件imagetest.php我有這樣的代碼部分:
<?php
require 'libs/image.php';
echo '<h1>HELLO WORLD : some html</h1>
<img src="'.displayImg_w('http://www.sanctius.net/wp-content/uploads/2010/05/Avatar-20.jpg',200).'">
';
在過去,我以前用定義圖像的$ _GET參數編寫URL ...但現在,我想直接在我的代碼中使用該函數。
的問題是圖像被正確顯示,但
的Hello World
HTML代碼沒有被瀏覽器(我知道的標題已經由第一代碼發送翻譯......但我想知道如何。正確顯示圖像,而不會影響HTML代碼,也沒有使用該圖片的URL改變這種不希望的形式獲取參數:庫/ image.php圖片= HTTP://www.example .com/image & width = 200
謝謝你提前。
FoRMat YoUr COdE ReAlLy讓它可以在眼睛上享受! – Shef
我編輯它SHEF :-) – SmootQ