Jump to content
xisto Community
Stenno

Get A Image Indentifier With Gd Library GD library question

Recommended Posts

Hey fellow coders,

 

I'm having a problem. If you output a im indentifier in php with gd libary. With this method for example:

 

<?header("(anti-spam-(anti-spam-(anti-spam-content-type:))) image/png");$imgWidth = 50;$imgHeight = 50;$image=imagecreate($imgWidth, $imgHeight);$colorBlack = imagecolorallocate($image, 0, 0, 0);  // first color you define with colorallocate is also the color of the background of your imageimagepng ($image);imagedestroy ($image);// This gives you a page with a black image of 50x50 pixels.?>

If i look at the source code of that page, i see:

 

˙Ř˙ŕJFIF˙ţ;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 70

˙ŰC

 

 

#%$""!&+7/&)4)!"0A149;>>>%.DIC<H7=>;˙ŰC

;("(;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;˙ŔnĆ"˙Ä

˙Äľ}!1AQa"q2Ą#BąÁRŃđ$3br

%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz˘Ł¤ĽŚ§¨ŠŞ˛ł´ľśˇ¸šşÂĂÄĹĆÇČÉĘŇÓÔŐÖ×ŘŮÚáâăäĺćçčéęńňóôőö÷řůú˙Ä

˙Äľw!1AQaq"2BĄąÁ #3RđbrŃ

$4á%ń&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz˘Ł¤ĽŚ§¨ŠŞ˛ł´ľśˇ¸šşÂĂÄĹĆÇČÉĘŇÓÔŐÖ×ŘŮÚâăäĺćçčéęňóôőö÷řůú˙Ú?ń(˘


I get something similair to that. Now my question: How can i get back the image indentifier (the var $image in the sample code above), with only this weird code ??

 

Thanks very much in advance,

 

Though i fear not many people here know how this can be done :)

Edited by Stenno (see edit history)

Share this post


Link to post
Share on other sites

Replace the first instance of the image variable with

$image = @imagecreate($imgWidth, $imgHeight);
Then check the page out again.

Share this post


Link to post
Share on other sites

Ohw sorry, thanks for warning. But that's not my question. It's just a quick sample script to explain my question better. Please read it carefully: i would like to know how i can recreate an image with only the weird data (in the quotes).

Share this post


Link to post
Share on other sites

The weird data should be the image itself, it's like opening up an image in an ascii editor. Check out these functions: imagecreatefrompng, imagecreatefromjpeg, imagecreatefromgif, etc..

Share this post


Link to post
Share on other sites

imagecreatefromjpeg ? Create a new image from file or URL

And i don't have a file, i only have a string with those weird chars. Or maybe there is some function to create a file first and then use imagecreatefromjpeg() ??

Share this post


Link to post
Share on other sites

Sten,

 

Maybe simply tell us exactly what you are trying to do here.

You appear to be writing a script to dynamically create an image. And now you want to save it? Why? Just use the script when you need the image...

If you really need to save a copy of the actual Image, run that script in your Browser and do a rt-click, save image as... to save it to your desktop.

That's the beauty of the script, you don't need to save the image :)

Share this post


Link to post
Share on other sites

Now my question: How can i get back the image indentifier (the var $image in the sample code above), with only this weird code ??

Put simply, I don't think you can. What you are asking to do is something similar to opening a binary file in a text editor, saving it, then trying to run it as a binary file - it just can't be done. For example, if you open the TuxKart binary in Kate, you get something like the following repeated for 8000 lines:
ELF		      4   d	 4    (      4   44               4  44            		 E E 	  	  p p\  , 	      ȘȘ             H  HH		      Ptd <B  <B        Qtd					      /lib/ld-linux.so.2           GNU	    	       _   (        )		  >	     	    G  (           5     	             		      :   /  6    	  i     2    e  -   	        	   ]     p   u		  j  :               

There is absolutely no way to turn that back into the binary to be able to use it again. This is pretty much what you are asking to do with your image. Perhaps if you explained why you need to convert the 'code' back into the variable, we might be able to give you a different method.

Share this post


Link to post
Share on other sites

I already found the method to retrieve an image indentifier with only the weird code. It's like this:

<?   $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'	   . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'	   . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'	   . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';   //$data is the base64_encoded weird data$data = base64_decode($data);$im = imagecreatefromstring($data);if ($im !== false) {	header('(anti-spam-content-type:) image/png');	imagepng($im);}else {	echo 'An error occurred.';}  ?>

Thanks for your help though, and sorry for the weird explenation

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.