2012-04-22 3 views
0

サムネイルを生成するために見つかったスクリプトを使用していますが、3行目と4行目の最初にエラーが発生しています。機能の1つが廃止予定です(それは一歳ですが)、私は本当に分かりません。 GDサポートが有効になっています。私はリンクされた質問を読んでいると私は約issetについて取得していない何かが実現しているが、私は両方の 'イメージ'と '幅'のためにこれを書く方法はわからない、それはまた、ライン。すべての助けに感謝します。サムネイル生成スクリプトの最初の行で未定義のインデックス

Notice: Undefined index: image in C:\xampp\htdocs\thumbnail\thumbnail.php on line 3

Notice: Undefined index: width in C:\xampp\htdocs\thumbnail\thumbnail.php on line 4

<?php 

$imageSrc = (string)$_GET['image'];  
$width = $_GET['width']; 

if (is_numeric($width) && isset($imageSrc)){ 
    header('Content-type: image/jpeg'); 
    makeThumb($imageSrc, $width); 
} 

function makeThumb($src,$newWidth) { 
    // read the source image given 
    $srcImage = imagecreatefromjpeg($src); 
    $width = imagesx($srcImage); 
    $height = imagesy($srcImage); 

    // find the height of the thumb based on the width given 
    $newHeight = floor($height*($newWidth/$width)); 

    // create a new blank image 
    $newImage = imagecreatetruecolor($newWidth,$newHeight); 

    // copy source image to a new size 
    imagecopyresized($newImage,$srcImage,0,0,0,0,$newWidth,$newHeight,$width,$height); 

    // create the thumbnail 
    imagejpeg($newImage); 
} 
?> 

私はすべてのページのロードのためのオンザフライで生成するスクリプトを実現し、効率的ではありませんが、私はちょうど働く何かを取得しようとしています。

私はローレンスによって提案された第三変更を行ったし、私はまだエラーを取得しています:

Notice: Undefined variable: width in C:\xampp\htdocs\thumbnail\thumbnail.php on line 13

+0

これは、クエリパラメータなしでスクリプトを呼び出すことを意味します。 'http://example.com/script.php?image = X&width = Y'の代わりに' http:// example.com/script.php'を入力してください。 –

答えて

0

使用isset

をお試しください
$imageSrc = isset($_GET['image']) ? $_GET['image'] : null;  
$width = isset($_GET['width']) ? $_GET['width'] : null ; 
0

あなたが使用する前に、そこに設定を確認する必要があります。

変更:

$imageSrc = (string)$_GET['image'];  
$width = $_GET['width']; 

~

$imageSrc = (isset($_GET['image']))?$_GET['image']:null;  
$width = (isset($_GET['width']))?$_GET['width']:null; 

場合、または他の方法

if(isset($_GET['image'])){$imageSrc = $_GET['image'];}else{$imageSrc =null;} 
if(isset($_GET['width'])){$width = $_GET['width'];}else{$width =null;} 

それとも、THOS 2行を忘れ、ちょうど行うことができます。

if (isset($_GET['width']) && is_numeric($_GET['width']) && isset($_GET['image'])){ 
    header('Content-type: image/jpeg'); 
    makeThumb(basename($_GET['image']), $_GET['width']); 
} 
+0

if(isset($ _ GET ['width'])&& is_numeric($ _ GET ['width'])&& isset($ _ GET ['image'])){ header( 'Content-type:image/jpeg') ; makeThumb($ _GET ['イメージ']、$ _GET ['幅']); } // $ imageSrc =(文字列)$ _ GET ['イメージ']; // $ width = $ _GET ['width']; if(is_numeric($ width)&& isset($ imageSrc)){ \t header( 'Content-type:image/jpeg'); \t makeThumb($ imageSrc、$ width); }はスクリプトの最初の部分をどのようにすべきか?私はまだエラーが発生しています:注意:未定義の変数:13行目のC:\ xampp \ htdocs \ thumbnail \ thumbnail.phpの幅。 – expiredninja

関連する問題