2017-01-18 10 views
2

これはbase64イメージを生成するために使用するコードです。ローカルホスト上では完全に動作しますが、リモートホスト上では異なる出力を生成します。GDイメージ(imagecreatefrompng)で使用されるbase64_encode()メソッドは、ローカルホストとリモートホストで異なる出力を表示します

<?php 
 
//Your Image 
 
$imgSrc = "http://pngimg.com/upload/water_PNG3290.png"; 
 
//getting the image dimensions 
 

 
list($width, $height) = getimagesize($imgSrc); 
 
$dif = $width - $height; 
 
//saving the image into memory (for manipulation with GD Library) 
 
$myImage = imagecreatefrompng($imgSrc); 
 
imageAlphaBlending($myImage, true); 
 
// calculating the part of the image to use for thumbnail 
 
if ($width > $height) { 
 
    $y = $width/13; //width 
 
    $x =$width/2.8 ; //height 
 
    $smallestSide = ($width - $height) /(0.002 * $dif); 
 
} else { 
 
    $x = 0; 
 
    $y = ($height - $width); 
 
    $smallestSide = $width; 
 
} 
 
// copying the part into thumbnail 
 
$thumbSize = 381; 
 
$thumb = imagecreatetruecolor($thumbSize, $thumbSize); 
 
imagefill($thumb,0,0,0x7fff0000); 
 
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide); 
 
imagealphablending($thumb, false); 
 
imagesavealpha($thumb, true); 
 
//final output 
 
ob_start(); 
 
    imagepng ($thumb); 
 
    $image_data = ob_get_contents(); 
 
ob_end_clean(); 
 
$image_data_base64 = base64_encode ($image_data); 
 
echo "<img src='data:image;base64,".$image_data_base64."'/>"; 
 
?>

答えて

0

これは単なる推測であり、私は間違っているかもしれないが、多分問題は、異なるPHPのバージョンおよび/または画像の一部のヘッダーです。

PNGなどのグラフィック形式は、かなりcomplexです。同じように表示される画像は、内部的に異なる場合があります。たとえば、PNGに作成日や最終変更日が含まれていて、mayが画像のバイナリ出力に影響します。

また、結果は実際のフォーマットの実装によって異なりますが、時間によって異なります。画像操作に使用しているGD関数のいずれかが変更される可能性があり、視覚的には同一のままですが、結果は異なります。

一般に、イメージをバイナリ文字列として比較しようとしないでください。この操作は信頼できません。

関連する問題