0

サムネイルを生成するために見つけたスクリプトを使用していますが、3行目と4行目の最初のエラーが発生しています。関数の1つが非推奨になっていると思います(1年前です)が、実際にはありませんアイディア。GDサポートが有効になっています。リンクされた質問を読んでいてisset、うまくいかないことがあることに気づきましたが、「画像」と「幅」の両方にこれを書く方法がわかりません。次の数行で設定されているようです。 。すべての助けに感謝します。

注意:未定義のインデックス:3行目のC:\ xampp \ htdocs \ thumbnail\thumbnail.phpの画像

注意:未定義のインデックス:4行目のC:\ xampp \ htdocs \ thumbnail\thumbnail.phpの幅

<?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); 
} 
?>

ページを読み込むたびにその場でスクリプトを生成するのは効率的ではないことに気づきましたが、何かを機能させようとしているだけです。

ローレンスによって提案された3番目の変更を行いましたが、まだエラーが発生しています。

注意:未定義の変数:13行目のC:\ xampp \ htdocs \ thumbnail\thumbnail.phpの幅

4

2 に答える 2

1

使用する前に、そこに設定されていることを確認する必要があります。

変化する:

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

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

またはifelseの方法

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

または、2行を忘れて、次のようにすることもできます。

if (isset($_GET['width']) && is_numeric($_GET['width']) && isset($_GET['image'])){ 
    header('Content-type: image/jpeg');
    makeThumb(basename($_GET['image']), $_GET['width']); 
}
于 2012-04-22T20:17:07.673 に答える
0

使用するisset

試す

$imageSrc = isset($_GET['image']) ? $_GET['image'] : null;    
$width = isset($_GET['width']) ? $_GET['width'] : null ; 
于 2012-04-22T20:17:28.810 に答える