2

This is the code I use to generate the base64 image. it works perfectly on local host but, however it generates a different output on a remote host.

<?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."'/>"; 
?>
miken32
  • 42,008
  • 16
  • 111
  • 154

1 Answers1

0

This is just a guess, and i may be wrong, but maybe the problem is different versions of PHP and/or some headers of the image.

The PNG and other graphic formats are quite complex. Images that are displayed identically may be different internally. For example, PNG may contains a date of creation or last modification and it may affect the binary output of the image.

Also the result depends on actual format implementation which varies with time. Any of GD-function that you are using for image manipulation can change something and results will be different, although visually they remain identical.

In general don't try to compare images as binary strings, this operation is unreliable.

Timurib
  • 2,735
  • 16
  • 29