 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
12-26-2008, 10:48 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
ARRGH! GD!!!!!!!!! help..
PHP Code:
class image
{
public function text($variable)
{
$image = imagecreate(200,25);
imagecolorallocate($image, 255, 255, 255);
$fontColor = imagecolorallocate($image, 0, 0, 0);
$startX = 15;
$startY = 5;
$string = "$variable";
imagestring($image, 3, $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:
Warning: Cannot modify header information - headers already sent by (output started at C:\DIR:3) in C:\class.php on line 65
�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隱^?ĺ]bmxi$M6nڨY?WcdnX;}v_J^9Ѽ|Q9-)) @Eq _z^wl\eո]P9*ԞNTN+ ( ( ( ( ( ( ( ( ( ( n*巸9 I]H#TP h*$YΖ$§+ ';W+r(�(�(�(�(�(�(�(�(�(�(�(
|
|
|
12-26-2008, 05:55 PM
|
#2 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
12-26-2008, 06:41 PM
|
#3 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
PHP Code:
class image { public function text($variable) { ob_start(); $image = imagecreate(200,25);
imagecolorallocate($image, 255, 255, 255);
$fontColor = imagecolorallocate($image, 0, 0, 0);
$startX = 15; $startY = 5; $string = "$variable"; imagestring($image, 3, $startX, $startY, $string, $fontColor); header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); ob_end_flush(); } } $image = new image();
isn't working for me :(
|
|
|
12-26-2008, 07:15 PM
|
#4 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
12-26-2008, 07:39 PM
|
#5 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
No , the only thing I can think of is include('clasess.php'); that has the image class which is sending the header.
|
|
|
12-26-2008, 10:32 PM
|
#6 (permalink)
|
|
The Wanderer
Join Date: Nov 2008
Location: Plymouth, UK
Posts: 9
Thanks: 0
|
I understand that whitespace after the ?> php tag can cause problems with header stuff, you checked that?
|
|
|
|
12-26-2008, 11:56 PM
|
#7 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
|
Maybe try putting the header at the top above the class.
|
|
|
12-30-2008, 07:41 AM
|
#8 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
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($image, 255, 255, 255);
$fontColor = imagecolorallocate($image, 0, 0, 0);
$startX = 15; $startY = 5; $string = "$variable"; imagestring($image, 3, $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���
|
|
|
12-30-2008, 03:59 PM
|
#9 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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..
|
|
|
|
12-30-2008, 06:20 PM
|
#10 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
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���
|
|
|
12-31-2008, 10:04 AM
|
#11 (permalink)
|
|
The Wanderer
Join Date: Oct 2008
Posts: 18
Thanks: 0
|
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($image, 255, 255, 255);
$fontColor = imagecolorallocate($image, 0, 0, 0);
$startX = 15; $startY = 5; $string = "$variable"; imagestring($image, 3, $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.
|
|
|
|
12-31-2008, 04:42 PM
|
#12 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by tego10122
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?
|
|
|
|
01-01-2009, 08:42 PM
|
#13 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
Quote:
Originally Posted by Village Idiot
Is it at the very top of the script?
|
Yes
PHP Code:
header('Content-type: image/jpeg');
$image = imagecreate(200,25);
imagecolorallocate($image, 255, 255, 255);
$fontColor = imagecolorallocate($image, 0, 0, 0);
$startX = 15;
$startY = 5;
$string = "$variable";
imagestring($image, 3, $startX, $startY, $string, $fontColor);
imagejpeg($image);
imagedestroy($image);
|
|
|
01-01-2009, 08:44 PM
|
#14 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
Quote:
Originally Posted by kokjj87
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($image, 255, 255, 255);
$fontColor = imagecolorallocate($image, 0, 0, 0);
$startX = 15;
$startY = 5;
$string = "$variable";
imagestring($image, 3, $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.
|
|
|
01-02-2009, 08:58 AM
|
#15 (permalink)
|
|
The Wanderer
Join Date: Oct 2008
Posts: 18
Thanks: 0
|
This is already a string to image script... i have attach a working attachment for you to try out. 
|
|
|
|
01-02-2009, 09:47 PM
|
#16 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
works pretty well, but wouldn't that be a hazard because anyone could use my website to generate text and kill my bandwith..
|
|
|
01-02-2009, 10:16 PM
|
#17 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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)
|
|
|
|
01-03-2009, 03:01 AM
|
#18 (permalink)
|
|
The Wanderer
Join Date: Oct 2008
Posts: 18
Thanks: 0
|
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 04:49 AM.
|
|
|
|
01-11-2009, 09:29 AM
|
#19 (permalink)
|
|
The Contributor
Join Date: Sep 2008
Location: Miami
Posts: 39
Thanks: 7
|
How would I cache it?
|
|
|
01-14-2009, 10:17 PM
|
#20 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
|
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
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|