2016-10-11 16 views
-2

解決済み問題!!!PHPで画像を作成し、サーバフォルダに保存する

  1. モニは私がimagejpegに3つのパラメータを渡す必要がありますが、小さな修正は、それがimagejpeg($im,$save,100)画質が品質の写真を得るためになければならないことになってimagejpeg($im,$save,0)すべきではないと述べたよう

  2. 画像フォルダが適切な出力を得るために、スラッシュ「画像/ FB /」imagecolorallocateimagecolorallocate($im, 142, 011, 029) 3桁のまた

  3. RGBなしです。

ので、このための答えと完全なコードは以下の通りである

<?php 
// Create image with 2 line of text 
$im = imagecreatetruecolor(600, 300); 
$text_color = imagecolorallocate($im, 142, 011, 029); 
imagestring($im, 10, 5, 5, 'Some Text String', $text_color); 
imagestring($im, 10, 5, 50, 'Some Text String 2', $text_color); 

// Set the content type header as image/jpeg 
header('Content-Type: image/jpeg'); 

// Output the image 
//imagejpeg($im); //up-to this point its working well 

$name="test2"; 
$save = "images/fb/". strtolower($name) .".jpeg"; 
imagejpeg($im, $save, 100); //Saves the image 
imagejpeg($im);    //Displays the image 

// Free up memory 
imagedestroy($im); 
?> 

問題

私はこの問題を解決するために私を助けてください、

I PHPで画像を作成しようとしていて、作成した画像をフォルダ内に保存しようとしましたが、画像が表示されましたが、フォルダに保存を追加すると、私には誤りです。以下は私が試したコードです。

<?php 
// Create image with 2 line of text 
$im = imagecreatetruecolor(600, 300); 
$text_color = imagecolorallocate($im, 142, 11, 29); 
imagestring($im, 10, 5, 5, 'Some Text String', $text_color); 
imagestring($im, 10, 5, 50, 'Some Text String 2', $text_color); 

// Set the content type header as image/jpeg 
header('Content-Type: image/jpeg'); 

// Output the image 
//imagejpeg($im); //up-to this point its working well 

$name="test"; 
$save = "/images/fb/". strtolower($name) .".jpeg"; 

imagejpeg($im, $save, 0, NULL); 

// Free up memory 
imagedestroy($im); 
?> 

次私は私のフォルダ構造は、私もchmodで試してみましたが、その私はだから許可が問題ではないようです

->www 
    -> projectFolder 
    -> subFolder 
     ->phpFile 
     ->imageFolder (images) 
     ->imageSubFolder (fb) 

ある

The image "path" cannot be displayed because it contains errors. 

を取得していますエラーですLocalhostでこれを試してみてください。

何かアドバイスをいただければ幸いです

...

+0

はあなたですパス '/ images/fb /'が存在することを確認してください。 '/'はローカルの 'images/fb /'フォルダではなくサーバー上のメインフォルダであることを意味します – nospor

+1

おそらくあなたのパスは間違っていますか?エラーは何ですか? –

+1

_ "...それは私にエラーを与えている" _ ...そしてエラーは何ですか? –

答えて

1

あなたが$imとしてイメージを作成し、.$my_img

変更としてそれを保存しようと、この:imagejpeg($my_img, $save, 0);

へ:imagejpeg($im, $save, 0);

+0

はい、これは間違いですが、同じ問題があっても「訂正」されています:( – Darshan

+0

そして、明らかにするために、** Null **はPHPマニュアルに従って 'imagejpeg'のパラメータとしても使用できます。画像の品質は – Darshan

+0

imagejpegには3つのパラメータしかありません。品質を設定し、$ toパラメータを指定したくない場合は、$ toパラメータにNULLを使用できます:http://php.net/manual/ en/function。imagejpeg.php –

関連する問題