TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-26-2008, 09:48 AM   #1 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default ARRGH! GD!!!!!!!!! help..

PHP Code:
    class image
    
{
        public function 
text($variable)
        {
            
$image imagecreate(200,25);

            
imagecolorallocate($image255255255);

            
$fontColor imagecolorallocate($image000);

            
$startX     15;
            
$startY     5;
            
$string "$variable";
            
imagestring($image3$startX$startY$string$fontColor);
            
header("Content-type: image/jpeg");
            
imagejpeg($image);
            
imagedestroy($image);
        }
    }
    
$image = new image(); 
When ever I do
PHP Code:
<?=$image->text('user@email.com');?>
I get
PHP Code:
WarningCannot modify header information headers already sent by (output started at C:\DIR:3in C:\class.php on line 65
&#65533;JFIF�������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality �C�      $.' ",#(7),01444'9=82<.342�C   2!!22222222222222222222222222222222222222222222222222���"������������  ����}�!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������  ���w�!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz� ��?�(+G;p}3z隱^?ĺ΁]bm‚xi$M6nڨY?WcdnX;}v_J^9Ѽ|Q9-)) @Eq _z^wl\eո]P9*ԞNTN+ ( ( ( ( ( ( ( ( ( ( n*巸9  I]H#TP h*$YΖ$§+ ';W+r(�(�(�(�(�(�(�(�(�(�(�( 
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-26-2008, 04:55 PM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Works for me, try wrapping it in ob_start and ob_end_flush
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 12-26-2008, 05:41 PM   #3 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

PHP Code:
  class image
    
{
        public function 
text($variable)
        {
ob_start();
            
$image imagecreate(200,25);

            
imagecolorallocate($image255255255);

            
$fontColor imagecolorallocate($image000);

            
$startX     15;
            
$startY     5;
            
$string "$variable";
            
imagestring($image3$startX$startY$string$fontColor);
            
header("Content-type: image/jpeg");
            
imagejpeg($image);
            
imagedestroy($image);
ob_end_flush();
        }
    }
    
$image = new image(); 
isn't working for me :(
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-26-2008, 06:15 PM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

something is sending headers out to the browser before your script can, you got other scripts running?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 12-26-2008, 06:39 PM   #5 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

No , the only thing I can think of is include('clasess.php'); that has the image class which is sending the header.
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-26-2008, 09:32 PM   #6 (permalink)
The Wanderer
 
Join Date: Nov 2008
Location: Plymouth, UK
Posts: 9
Thanks: 0
Measter is on a distinguished road
Default

I understand that whitespace after the ?> php tag can cause problems with header stuff, you checked that?
Measter is offline  
Reply With Quote
Old 12-26-2008, 10:56 PM   #7 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

Maybe try putting the header at the top above the class.
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 12-30-2008, 06:41 AM   #8 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

Still not working, im just trying to make a simple class that will render the variable into an image
PHP Code:
 $image->text('email@email.com'); -> gd image 
Heres my new code
PHP Code:
    class image
    
{
        public function 
text($variable)
        {
            
ob_start();
            
$image imagecreate(200,25);
            
imagecolorallocate($image255255255);

            
$fontColor imagecolorallocate($image000);

            
$startX     15;
            
$startY     5;
            
$string "$variable";
            
imagestring($image3$startX$startY$string$fontColor);

            
imagejpeg($image);
            
imagedestroy($image);
            
ob_flush();
        }
    }
    
$image = new image(); 
This is what i get...
Code:
�����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ���C�    $.' ",#(7),01444'9=82<.342���C  2!!22222222222222222222222222222222222222222222222222������"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%� &'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ��?���(�獦��$�HЪ�R�H��p##� �PhJ+��'�K���`ү.���n�Ka%���A�tbp�k���df#nv��ƞ%�ӧ���V:�����Y�i�o��- ϑ##�W)ʱ�Z��+��OV��4�WU�g���Ƣ;ؒ(�i �UCJSk�)��`�{F��[�����V�D�;��1<�W���@QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE���
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-30-2008, 02:59 PM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,298
Thanks: 17
Village Idiot is on a distinguished road
Default

You are outputting the image as text, put the following line of code at the top of the script to tell the browser that we are working with an image:
header('Content-type: image/jpeg');

When a browser receives content, it must be told what it is. Since most things a browser displays are text, that is the default. So if you are displaying some other file format, the browser has to know. Headers is how you tell it what its dealing with..
__________________

Village Idiot is offline  
Reply With Quote
Old 12-30-2008, 05:20 PM   #10 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

Code:
    * Warning: Cannot modify header information - headers already sent by (output started at C:\www\page.php:3) in C:\www\lib\clasess.php on line 64
      �����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ���C�    $.' ",#(7),01444'9=82<.342���C  2!!22222222222222222222222222222222222222222222222222������"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%� &'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ��?���(�獦��$�HЪ�R�H��p##� �PhJ+��'�K���`ү.���n�Ka%���A�tbp�k���df#nv��ƞ%�ӧ���V:�����Y�i�o��- ϑ##�W)ʱ�Z��+��OV��4�WU�g���Ƣ;ؒ(�i �UCJSk�)��`�{F��[�����V�D�;��1<�W���@QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE���
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 12-31-2008, 09:04 AM   #11 (permalink)
The Wanderer
 
kokjj87's Avatar
 
Join Date: Oct 2008
Posts: 18
Thanks: 0
kokjj87 is on a distinguished road
Default

You can't have both html and picture render in the same page, because the header("Content-type: image/jpeg"); header would tell the browser to render it as a jpg page, instead of a html page..

In order to get this working, you need to separate this 2 file.


//The image file
PHP Code:
<?php
$text 
$_GET['text'];

class 
image
    
{
        public function 
text($variable)
        {
            
$image imagecreate(200,25);

            
imagecolorallocate($image255255255);

            
$fontColor imagecolorallocate($image000);

            
$startX     15;
            
$startY     5;
            
$string "$variable";
            
imagestring($image3$startX$startY$string$fontColor);
            
header("Content-type: image/jpeg");
            
imagejpeg($image);
            
imagedestroy($image);
        }
    }
    
$image = new image();
    echo 
$image->text($text);
?>


//the html page
PHP Code:
<?php
echo 'this is the html page.<br/>';
echo 
'<img src="PATHTOTHEIMAGEFILE?text=YOUR TEXT HERE"/>';
?>

Since your are parsing a email, so it is quite sensitive, so rather than passing the email as the parameter, i would recommend you to query the database and get the email for parsing on your image side.
kokjj87 is offline  
Reply With Quote
Old 12-31-2008, 03:42 PM   #12 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,298
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by tego10122 View Post
Code:
    * Warning: Cannot modify header information - headers already sent by (output started at C:\www\page.php:3) in C:\www\lib\clasess.php on line 64
      �����JFIF���������>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ���C�    $.' ",#(7),01444'9=82<.342���C  2!!22222222222222222222222222222222222222222222222222������"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%� &'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ��?���(�獦��$�HЪ�R�H��p##� �PhJ+��'�K���`ү.���n�Ka%���A�tbp�k���df#nv��ƞ%�ӧ���V:�����Y�i�o��- ϑ##�W)ʱ�Z��+��OV��4�WU�g���Ƣ;ؒ(�i �UCJSk�)��`�{F��[�����V�D�;��1<�W���@QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE�QE���
Is it at the very top of the script?
__________________

Village Idiot is offline  
Reply With Quote
Old 01-01-2009, 07:42 PM   #13 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
Is it at the very top of the script?
Yes
PHP Code:

            header
('Content-type: image/jpeg');
            
$image imagecreate(200,25);
            
imagecolorallocate($image255255255);

            
$fontColor imagecolorallocate($image000);

            
$startX     15;
            
$startY     5;
            
$string "$variable";
            
imagestring($image3$startX$startY$string$fontColor);
            
            
imagejpeg($image);
            
imagedestroy($image); 
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 01-01-2009, 07:44 PM   #14 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

Quote:
Originally Posted by kokjj87 View Post
You can't have both html and picture render in the same page, because the header("Content-type: image/jpeg"); header would tell the browser to render it as a jpg page, instead of a html page..

In order to get this working, you need to separate this 2 file.


//The image file
PHP Code:
<?php
$text 
$_GET['text'];

class 
image
    
{
        public function 
text($variable)
        {
            
$image imagecreate(200,25);

            
imagecolorallocate($image255255255);

            
$fontColor imagecolorallocate($image000);

            
$startX     15;
            
$startY     5;
            
$string "$variable";
            
imagestring($image3$startX$startY$string$fontColor);
            
header("Content-type: image/jpeg");
            
imagejpeg($image);
            
imagedestroy($image);
        }
    }
    
$image = new image();
    echo 
$image->text($text);
?>


//the html page
PHP Code:
<?php
echo 'this is the html page.<br/>';
echo 
'<img src="PATHTOTHEIMAGEFILE?text=YOUR TEXT HERE"/>';
?>

Since your are parsing a email, so it is quite sensitive, so rather than passing the email as the parameter, i would recommend you to query the database and get the email for parsing on your image side.


I see what you are saying, but im basically trying to use this string to generate text into image , not to watermark images.
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 01-02-2009, 07:58 AM   #15 (permalink)
The Wanderer
 
kokjj87's Avatar
 
Join Date: Oct 2008
Posts: 18
Thanks: 0
kokjj87 is on a distinguished road
Default

This is already a string to image script... i have attach a working attachment for you to try out.
Attached Files
File Type: zip test.zip (577 Bytes, 5 views)
kokjj87 is offline  
Reply With Quote
Old 01-02-2009, 08:47 PM   #16 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

works pretty well, but wouldn't that be a hazard because anyone could use my website to generate text and kill my bandwith..
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 01-02-2009, 09:16 PM   #17 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Its possible yes, if you use GET.
I suppose you could faff around checking referrer headers etc but there not reliable.

Shouldnt be a problem if you only use a value defined by you (as in your first example). If it were me I would generate the images in a managed environment, for example when the user registers/changes his/her email address, then just display the img (from db/file system) instead of having to completely rebuild the image from scratch every time. That will also save a bit of the servers CPU power for other things (albeit not alot, it all adds up you know!).
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-03-2009, 02:01 AM   #18 (permalink)
The Wanderer
 
kokjj87's Avatar
 
Join Date: Oct 2008
Posts: 18
Thanks: 0
kokjj87 is on a distinguished road
Default

Don't worried man, i see most of the website are doing this. =D... I agree to SketchMedia, if you have a high traffic on your website, save the generate image to the hardisk instead.

If you do not want to save to your hardisk, Query the database for the email in the image.php file, that means that this image.php is only usable by you and useless for other website. That is what i always do.

Last edited by kokjj87 : 01-03-2009 at 03:49 AM.
kokjj87 is offline  
Reply With Quote
Old 01-11-2009, 08:29 AM   #19 (permalink)
The Contributor
 
tego10122's Avatar
 
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
tego10122 is on a distinguished road
Default

How would I cache it?
__________________
You're Everyday Graphic Artist
Twitter|GigPark|Linked In
Send a message via MSN to tego10122
tego10122 is offline  
Reply With Quote
Old 01-14-2009, 09:17 PM   #20 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

what editor were you using to create that? i have noticed a few editors out there place junk characters before the <?php tag and when you try to output something it gives that header error thing. next time try opening the file in notepad and see if you see junk characters in it.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 03:53 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design