Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Get A Image Indentifier With Gd Library, GD library question
Stenno
post Oct 7 2007, 05:21 PM
Post #1


Newbie [Level 1]
*

Group: [HOSTED]
Posts: 21
Joined: 29-September 07
Member No.: 50,836



Hey fellow coders,

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

CODE
<?
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 image

imagepng ($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:

QUOTE
�JFIF�������;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 70
�C�





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

;("(;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;��n�"������������
����}�!1AQa"q2#BR$3br
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
��������
���w�!1AQaq"2B #3Rbr
$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 unsure.gif[size="3"][/size]

This post has been edited by Stenno: Oct 7 2007, 08:02 PM
Go to the top of the page
 
+Quote Post
truefusion
post Oct 7 2007, 07:35 PM
Post #2


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,918
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528



Replace the first instance of the image variable with
CODE
$image = @imagecreate($imgWidth, $imgHeight);

Then check the page out again.
Go to the top of the page
 
+Quote Post
Stenno
post Oct 7 2007, 08:01 PM
Post #3


Newbie [Level 1]
*

Group: [HOSTED]
Posts: 21
Joined: 29-September 07
Member No.: 50,836



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).
Go to the top of the page
 
+Quote Post
truefusion
post Oct 8 2007, 12:02 AM
Post #4


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,918
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528



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..
Go to the top of the page
 
+Quote Post
Stenno
post Oct 8 2007, 05:20 AM
Post #5


Newbie [Level 1]
*

Group: [HOSTED]
Posts: 21
Joined: 29-September 07
Member No.: 50,836



QUOTE
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() ??
Go to the top of the page
 
+Quote Post
jlhaslip
post Oct 8 2007, 05:31 AM
Post #6


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,081
Joined: 24-July 05
From: Linix, DOS and Windowsthe good, the bad and the ugly
Member No.: 9,787
Spam Patrol



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 smile.gif
Go to the top of the page
 
+Quote Post
rvalkass
post Oct 8 2007, 05:56 AM
Post #7


apt-get moo
Group Icon

Group: [MODERATOR]
Posts: 2,153
Joined: 28-May 05
From: Devon, England
Member No.: 7,593
Spam Patrol



QUOTE(Stenno @ Oct 7 2007, 06:21 PM) *
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:
CODE
ELF              ��4   d�     4    (      4   4�4�               4  4�4�                    � �E� E�           �  p p\  �,          � ȘȘ             H  H�H�              P�td� ����<B  <B        Q�td                          /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.
Go to the top of the page
 
+Quote Post
Stenno
post Oct 9 2007, 02:33 PM
Post #8


Newbie [Level 1]
*

Group: [HOSTED]
Posts: 21
Joined: 29-September 07
Member No.: 50,836



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

CODE
<?
   $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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Do You Use Imagefilez.com?(36)
  2. Testing Of The Auto Image Resizer(0)
  3. Finding The Rgb Color Of An Image(3)
  4. Wmp (windows Media Photo) - The New Image File Format From Microsoft(33)
  5. How To Create Embed Image Mail In Gmail(56)
  6. Image Preloader With Progress Bar Status(23)
  7. Idea For Using A Cron Job To Grab Daily Travian Map.sql Updates(3)
  8. How To Make Image Buttons Act As Submit Button(8)
  9. How To Create Cool Image Buttons(7)
  10. Problem Aligning In Firefox(9)
  11. Need To Shrink The File Size Of Web Image? - Photoshop Tricks(3)
  12. Render Request Please..(0)
  13. Watermark Your Image With Simple Php Script(35)
  14. Background Image Swap Script(15)
  15. Scrolling Images?(5)