TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   ARRGH! GD!!!!!!!!! help.. (http://www.talkphp.com/advanced-php-programming/3804-arrgh-gd-help.html)

tego10122 12-26-2008 10:48 AM

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(�(�(�(�(�(�(�(�(�(�(�( 


sketchMedia 12-26-2008 05:55 PM

Works for me, try wrapping it in ob_start and ob_end_flush

tego10122 12-26-2008 06:41 PM

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

sketchMedia 12-26-2008 07:15 PM

something is sending headers out to the browser before your script can, you got other scripts running?

tego10122 12-26-2008 07:39 PM

No , the only thing I can think of is include('clasess.php'); that has the image class which is sending the header.

Measter 12-26-2008 10:32 PM

I understand that whitespace after the ?> php tag can cause problems with header stuff, you checked that?

Rendair 12-26-2008 11:56 PM

Maybe try putting the header at the top above the class.

tego10122 12-30-2008 07:41 AM

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���

Village Idiot 12-30-2008 03:59 PM

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..

tego10122 12-30-2008 06:20 PM

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���


kokjj87 12-31-2008 10:04 AM

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.

Village Idiot 12-31-2008 04:42 PM

Quote:

Originally Posted by tego10122 (Post 20869)
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?

tego10122 01-01-2009 08:42 PM

Quote:

Originally Posted by Village Idiot (Post 20921)
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); 


tego10122 01-01-2009 08:44 PM

Quote:

Originally Posted by kokjj87 (Post 20916)
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.

kokjj87 01-02-2009 08:58 AM

1 Attachment(s)
This is already a string to image script... i have attach a working attachment for you to try out. 8-)

tego10122 01-02-2009 09:47 PM

works pretty well, but wouldn't that be a hazard because anyone could use my website to generate text and kill my bandwith..

sketchMedia 01-02-2009 10:16 PM

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!).

kokjj87 01-03-2009 03:01 AM

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.

tego10122 01-11-2009 09:29 AM

How would I cache it?

sarmenhb 01-14-2009 10:17 PM

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.


All times are GMT. The time now is 07:47 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0