2012-01-16 13 views
0

イメージファイルをバイナリに変換するプログラムと、バイナリデータをイメージファイルに変換するプログラムがあります。私は最初にやった、私はバイナリに画像ファイルを変換することができます。しかし、まだ行われていない第2のもの。 バイナリイメージデータをイメージファイルに変換し、それをphpのフォルダに保存する方法

は、変換した画像ファイルにバイナリデータを保存するためにどのように私はPHPでしなさいこれをチェックしています

は私

+0

「バイナリ」とはどういう意味ですか?あなたはあなたの問題を少し良く説明できますか? – Vyktor

+0

私はfile_get_contentsを使用して、それを文字列 –

答えて

3

hereを文書化されimagecreatefromstring方法を、試してみてください助けます。

+0

"It Works!"に変換しました。 。もう1つの質問ビデオファイルを同じ方法で変換することはできますか?どのように達成できますか? –

+0

@Rintoビデオファイルを変換するとどういう意味ですか?文字列をビデオに変換しますか? – Dau

+0

"ありがとう"はい、私が画像(文字列から画像)に使用したのと同じ方法です。私は他の非PHPアプリケーションから文字列データとしてビデオを取得しています。私はそれを私のサーバーにビデオファイルとして保存し、ビデオプレーヤーでストリーミングする必要があります。何か案は ? –

0

バイナリストリーム(私はr/g/b値と仮定します)を10進表記に変換し、imagesetpixel()を使用して作成しているイメージにピクセルを書き込みます。

画像データをバイナリストリームに変更するいくつかの理由の1つは、ステガノグラフィー中に2進ビットの下位ビットに追加データを隠すことです。人間の目には見えないレベルで各ピクセルの色を変更します。あなたがsaving an imageresizing saved png image without losing its transparent/white effectのオプションを使用してコードの下に使用することができます

チェックhttp://www.php.net/manual/en/function.imagesetpixel.php

1

$data = 'binary data of image'; 
$data = base64_decode($data); 
$im = imagecreatefromstring($data); 
// assign new width/height for resize purpose 
$newwidth = $newheight = 50; 
// Create a new image from the image stream in the string 
$thumb = imagecreatetruecolor($newwidth, $newheight); 

if ($im !== false) { 

    // Select the HTTP-Header for the selected filetype 
    #header('Content-Type: image/png'); // uncomment this code to display image in browser 

    // alter or save the image 
    $fileName = $_SERVER['DOCUMENT_ROOT'].'server location to store image/'.date('ymdhis').'.png'; // path to png image 
    imagealphablending($im, false); // setting alpha blending on 
    imagesavealpha($im, true); // save alphablending setting (important) 

    // Generate image and print it 
    $resp = imagepng($im, $fileName); 

    // resizing png file 
    imagealphablending($thumb, false); // setting alpha blending on 
    imagesavealpha($thumb, true); // save alphablending setting (important) 

    $source = imagecreatefrompng($fileName); // open image 
    imagealphablending($source, true); // setting alpha blending on 

    list($width, $height, $type, $attr) = getimagesize($fileName); 
    #echo '<br>' . $width . '-' . $height . '-' . $type . '-' . $attr . '<br>'; 

    imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); 
    $newFilename = $_SERVER['DOCUMENT_ROOT'].'server location to store image/resize_'.date('ymdhis').'.png'; 
    $resp = imagepng($thumb,$newFilename); 

    // frees image from memory 
    imagedestroy($im); 
    imagedestroy($thumb); 

} 
else { 
    echo 'An error occurred.'; 
} 

同じように、我々は、画像のJPEG、JPGやGIF形式のために行うことができます。

ここの人々に役立つことを祈っています!

関連する問題