0

私は次の問題に遭遇しました。私はgdでサムネイルを作成しましたが、Chromeで実行すると、次のようになります。

これはまさに私が期待していたことです(サイズを変更します)

Chromeで撮影したスクリーンショット

悲しいことに、これはFirefoxであり、つまり、次のようになります。

ffで撮影した画像

サイズ変更を処理する次のコードがあります。

// this image is created by another php file when text is filled in
$file = "hidden.png";
$size = GetImageSize($file);
if($size !== false){
$w = $size[0];
$h = $size[1];
//set new size
$nw = $_GET['width'];
$nh = ($nw*$h)/$w;
}
else{
//set new size
$nw = 400;
$nh = 200;
} 
//draw the image
$src_img = imagecreatefrompng($file);
$dst_img = imagecreatetruecolor($nw,$nh);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $w, $h);
//resizing the    image
imagepng($dst_img);
imagedestroy($src_img);
imagedestroy($dst_img);  

私はスタックとグーグルでビットを検索しました、そして私が見つけることができる唯一のものは私の画像がそのように構築されていないので私が必要としないcssを使用している解決策です。

すべてのブラウザで正しく機能させるには、コードごとに(css関連ではなく)何をする必要がありますか?

必要に応じて、さらにコードを投稿できます

4

2 に答える 2

0

それは間違いなくブラウザとは何の関係もありません。それはphpが機能する方法ではないからです。まず、php コードがサーバー上で解釈され、その結果がクライアント (ブラウザ) に渡されます。

したがって、私の意見では、最初に画像生成が正しく機能しているかどうかを確認する必要があります。毎回同じ画像を生成することを意味します。次に、この部分を確認する必要があります。

if($size !== false){
   $w = $size[0];
   $h = $size[1];
   $nw = $_GET['width']; // <---- For Debugging set here a static number
   $nh = ($nw*$h)/$w;
}

デバッグ部分では、リクエストごとに変更される可能性のあるすべての変数を修正値に設定してみてください。

お役に立てれば幸いです

于 2013-02-25T11:50:43.920 に答える
0

上記のスクリプトを既存のスクリプトとマージして画像を生成することで、問題を解決しました。

/* Get image info */
if(!isset($_POST['width']) && !isset($_POST['height']))
{
$width = '200';
$height = '100';
}
else
{
$width  = $_POST['width'] ;
$height = $_POST['height'];  
}
$Image = imagecreatetruecolor($width,$height) ;
$sx = imagesx($Image) ;
$sy = imagesy($Image) ;
/*Check if RGB values have been set*/
if(!isset($_POST['r'])) {     $R = 255; } else {     $R = $_POST['r']; } 
if(!isset($_POST['g'])) {     $G = 255; } else {     $G = $_POST['g']; } 
if(!isset($_POST['b'])) {     $B = 255; } else {     $B = str_replace(")" , "" ,  $_POST['b']); }

/*Check if the text value is set   */
if(!isset($_POST['text'])) {$Text = "Uw tekst hier";}
else if($_POST['text'] == '') {$Text = "Uw tekst hier";}
else {$Text = $_POST['text'];}

/*Check if the font is set */
if(!isset($_POST['font'])) {$Font="./Fonts/arial.ttf" ;}
else{$Font= "./fonts/".$_POST['font'].".ttf";}

$FontColor = ImageColorAllocate ($Image,$R,$G,$B) ;    //TextColor
$FontShadow = ImageColorAllocate ($Image,0,0,0) ;   //BackGroundColor
$Rotation = 0 ;
/* Iterate to get the size up */
$FontSize=1 ;
do
    {
    $FontSize *= 1.1 ;
    $Box = @ImageTTFBBox($FontSize,0,$Font,$Text);
    $TextWidth = abs($Box[2] - $Box[6]) ;
    $TextHeight = abs($Box[3] - $Box[7]) ;
    }
while ($TextWidth < $sx*0.94) ;
/*  Awkward maths to get the origin of the text in the right place */ 
$x = $sx/2  - cos(deg2rad($Rotation))*$TextWidth/2;
$y = $sy/2  + sin(deg2rad($Rotation))*$TextWidth/2 + cos(deg2rad($Rotation))*$TextHeight/2 ;


imagefilledrectangle($Image, 0, 0, $sx , $sy , $FontShadow);
ImageTTFText ($Image,$FontSize,$Rotation,-$Box[6] ,-$Box[7],$FontColor,$Font,$Text);

if(isset($_POST['resize']) && $_POST['resize'] == 1)
{
    $nw = 400;
    $nh = 200;        

    $src_img = $Image;
    $dst_img = imagecreatetruecolor($nw,$nh);
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $sx, $sy);//resizing    the image
    imagepng($dst_img, "hidden.png");
    imagedestroy($src_img);
    imagedestroy($dst_img); 
}
else
{
  //header('Content-type: image/png');
  Imagepng($Image, "hidden.png") ; 
}
于 2013-02-26T09:31:34.043 に答える