FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Newline (cr/lf) in imagestring
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Newline (cr/lf) in imagestring [message #182408] Sat, 03 August 2013 14:59 Go to next message
Ed Jay is currently offline  Ed Jay
Messages: 7
Registered: August 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
I'm merging text into an image using:

$msg = 'string1:' . $string1 . ' string2: ' . $string2;

$text = imagecreatetruecolor($width, $height);
imagestring($text, 5, 50, 50, $msg, 0x00ff00);
imagecopymerge($final, $text, 50, 50, 50, 50, $width, $height, 100);

The above works.

What I want to do is have ' string2: ' . $string2 show on a new line. How?

Anything with the quotes displays as a literal, e.g., '\r\n string2'
outputs as \r\n\string2, as does <br> and anything else, just as the
manual says it will. I tried adding the string PCP_EOL, but it didn't
play. I tried $msg = nl2br(string to output) with \r\n within the string,
but it doesn't play.

So...how do I produce cr/lf?
--
Ed Jay (remove 'M' to respond by email)
Re: Newline (cr/lf) in imagestring [message #182409 is a reply to message #182408] Sat, 03 August 2013 16:26 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
add to buddy list
ignore all messages by this user
On Saturday 03 August 2013 14:59, in comp.lang.php, edMbj(at)aes-intl(dot)com
wrote:

> I'm merging text into an image using:
>
> $msg = 'string1:' . $string1 . ' string2: ' . $string2;
>
> $text = imagecreatetruecolor($width, $height);
> imagestring($text, 5, 50, 50, $msg, 0x00ff00);
> imagecopymerge($final, $text, 50, 50, 50, 50, $width, $height, 100);
>
> The above works.
>
> What I want to do is have ' string2: ' . $string2 show on a new line. How?
>
> Anything with the quotes displays as a literal, e.g., '\r\n string2'
> outputs as \r\n\string2, as does <br> and anything else, just as the
> manual says it will. I tried adding the string PCP_EOL, but it didn't
> play. I tried $msg = nl2br(string to output) with \r\n within the string,
> but it doesn't play.
>
> So...how do I produce cr/lf?

The php.net description of the imagestring() function
(http://php.net/manual/en/function.imagestring.php) says that it draws "a
string horizontally".

I believe that the function is not constructed to draw multiple lines, but
only text in a single horizontal line.

So, to draw two strings, one line apart, you make two calls to
imagestring(), with two individual strings.

The second call should use the first call's x and y values, offset by the
font size (imagefontheight()) plus the amount of space between each line.

--
Lew Pitcher
"In Skills, We Trust"
Re: Newline (cr/lf) in imagestring [message #182410 is a reply to message #182409] Sat, 03 August 2013 16:31 Go to previous messageGo to next message
Ed Jay is currently offline  Ed Jay
Messages: 7
Registered: August 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Lew Pitcher wrote:

> On Saturday 03 August 2013 14:59, in comp.lang.php, edMbj(at)aes-intl(dot)com
> wrote:
>
>> I'm merging text into an image using:
>>
>> $msg = 'string1:' . $string1 . ' string2: ' . $string2;
>>
>> $text = imagecreatetruecolor($width, $height);
>> imagestring($text, 5, 50, 50, $msg, 0x00ff00);
>> imagecopymerge($final, $text, 50, 50, 50, 50, $width, $height, 100);
>>
>> The above works.
>>
>> What I want to do is have ' string2: ' . $string2 show on a new line. How?
>>
>> Anything with the quotes displays as a literal, e.g., '\r\n string2'
>> outputs as \r\n\string2, as does <br> and anything else, just as the
>> manual says it will. I tried adding the string PCP_EOL, but it didn't
>> play. I tried $msg = nl2br(string to output) with \r\n within the string,
>> but it doesn't play.
>>
>> So...how do I produce cr/lf?
>
> The php.net description of the imagestring() function
> (http://php.net/manual/en/function.imagestring.php) says that it draws "a
> string horizontally".
>
> I believe that the function is not constructed to draw multiple lines, but
> only text in a single horizontal line.
>
> So, to draw two strings, one line apart, you make two calls to
> imagestring(), with two individual strings.
>
> The second call should use the first call's x and y values, offset by the
> font size (imagefontheight()) plus the amount of space between each line.

Thanks.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info
Re: Newline (cr/lf) in imagestring [message #182411 is a reply to message #182409] Sat, 03 August 2013 16:53 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 03/08/13 21:26, Lew Pitcher wrote:
> On Saturday 03 August 2013 14:59, in comp.lang.php, edMbj(at)aes-intl(dot)com
> wrote:
>
>> I'm merging text into an image using:
>>
>> $msg = 'string1:' . $string1 . ' string2: ' . $string2;
>>
>> $text = imagecreatetruecolor($width, $height);
>> imagestring($text, 5, 50, 50, $msg, 0x00ff00);
>> imagecopymerge($final, $text, 50, 50, 50, 50, $width, $height, 100);
>>
>> The above works.
>>
>> What I want to do is have ' string2: ' . $string2 show on a new line. How?
>>
>> Anything with the quotes displays as a literal, e.g., '\r\n string2'
>> outputs as \r\n\string2, as does <br> and anything else, just as the
>> manual says it will. I tried adding the string PCP_EOL, but it didn't
>> play. I tried $msg = nl2br(string to output) with \r\n within the string,
>> but it doesn't play.
>>
>> So...how do I produce cr/lf?
> The php.net description of the imagestring() function
> (http://php.net/manual/en/function.imagestring.php) says that it draws "a
> string horizontally".
>
> I believe that the function is not constructed to draw multiple lines, but
> only text in a single horizontal line.
>
> So, to draw two strings, one line apart, you make two calls to
> imagestring(), with two individual strings.
>
> The second call should use the first call's x and y values, offset by the
> font size (imagefontheight()) plus the amount of space between each line.
>
+1 -= works for me.


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
Re: Newline (cr/lf) in imagestring [message #182412 is a reply to message #182408] Sat, 03 August 2013 17:01 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
In article <46kqv8d4tqhl15ripkbc1dfjb2m0tqvgtt(at)4ax(dot)com>,
Ed Jay <edMbj(at)aes-intl(dot)com> wrote:

> So...how do I produce cr/lf?

$lf = chr (10);
$cr = chr (13);
$nl = $cr . $lf;


Simples.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: Newline (cr/lf) in imagestring [message #182413 is a reply to message #182412] Sat, 03 August 2013 17:24 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
add to buddy list
ignore all messages by this user
On Saturday 03 August 2013 17:01, in comp.lang.php, timstreater(at)greenbee(dot)net
wrote:

> In article <46kqv8d4tqhl15ripkbc1dfjb2m0tqvgtt(at)4ax(dot)com>,
> Ed Jay <edMbj(at)aes-intl(dot)com> wrote:
>
>> So...how do I produce cr/lf?
>
> $lf = chr (10);
> $cr = chr (13);
> $nl = $cr . $lf;

Alternatively,

$lf = chr (37);
$cr = chr (13);
$nl = $cr . $lf;

or even

$nl = chr (21);

Control characters are very platform specific, don't you think?

> Simples.

Only if you restrict Ed's solution to the platform /you/ use.

--
Lew Pitcher
"In Skills, We Trust"
Re: Newline (cr/lf) in imagestring [message #182414 is a reply to message #182413] Sat, 03 August 2013 17:53 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
In article <zyeLt.331254$0a4(dot)83683(at)fx06(dot)iad>,
Lew Pitcher <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

> On Saturday 03 August 2013 17:01, in comp.lang.php, timstreater(at)greenbee(dot)net
> wrote:
>
>> In article <46kqv8d4tqhl15ripkbc1dfjb2m0tqvgtt(at)4ax(dot)com>,
>> Ed Jay <edMbj(at)aes-intl(dot)com> wrote:
>>
>>> So...how do I produce cr/lf?
>>
>> $lf = chr (10);
>> $cr = chr (13);
>> $nl = $cr . $lf;
>
> Alternatively,
>
> $lf = chr (37);
> $cr = chr (13);
> $nl = $cr . $lf;
>
> or even
>
> $nl = chr (21);
>
> Control characters are very platform specific, don't you think?
>
>> Simples.
>
> Only if you restrict Ed's solution to the platform /you/ use.

The OP asked for CR and LF, which is what I gave. 21 is NAK and 37 is %,
according to:

<http://www.asciitable.com>

Abyssinia.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
Re: Newline (cr/lf) in imagestring [message #182415 is a reply to message #182408] Sat, 03 August 2013 18:02 Go to previous messageGo to next message
Richard Damon is currently offline  Richard Damon
Messages: 58
Registered: August 2011
Karma: 0
Member
add to buddy list
ignore all messages by this user
On 8/3/13 2:59 PM, Ed Jay wrote:
> I'm merging text into an image using:
>
> $msg = 'string1:' . $string1 . ' string2: ' . $string2;
>
> $text = imagecreatetruecolor($width, $height);
> imagestring($text, 5, 50, 50, $msg, 0x00ff00);
> imagecopymerge($final, $text, 50, 50, 50, 50, $width, $height, 100);
>
> The above works.
>
> What I want to do is have ' string2: ' . $string2 show on a new line. How?
>
> Anything with the quotes displays as a literal, e.g., '\r\n string2'
> outputs as \r\n\string2, as does <br> and anything else, just as the
> manual says it will. I tried adding the string PCP_EOL, but it didn't
> play. I tried $msg = nl2br(string to output) with \r\n within the string,
> but it doesn't play.
>
> So...how do I produce cr/lf?
>

One thing to note,

$a = '\r\n'; will set $a to a string of 4 characters ( \ r \ n)

$b = "\r\n"; will set $b to a string of 2 characters, return and new-line

The type of quote around the string makes a big difference to how the
insides are parsed.
Re: Newline (cr/lf) in imagestring [message #182416 is a reply to message #182414] Sat, 03 August 2013 18:47 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
add to buddy list
ignore all messages by this user
On Saturday 03 August 2013 17:53, in comp.lang.php, timstreater(at)greenbee(dot)net
wrote:

> In article <zyeLt.331254$0a4(dot)83683(at)fx06(dot)iad>,
> Lew Pitcher <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
>
>> On Saturday 03 August 2013 17:01, in comp.lang.php,
>> timstreater(at)greenbee(dot)net wrote:
>>
>>> In article <46kqv8d4tqhl15ripkbc1dfjb2m0tqvgtt(at)4ax(dot)com>,
>>> Ed Jay <edMbj(at)aes-intl(dot)com> wrote:
>>>
>>>> So...how do I produce cr/lf?
>>>
>>> $lf = chr (10);
>>> $cr = chr (13);
>>> $nl = $cr . $lf;
>>
>> Alternatively,
>>
>> $lf = chr (37);
>> $cr = chr (13);
>> $nl = $cr . $lf;
>>
>> or even
>>
>> $nl = chr (21);
>>
>> Control characters are very platform specific, don't you think?
>>
>>> Simples.
>>
>> Only if you restrict Ed's solution to the platform /you/ use.
>
> The OP asked for CR and LF, which is what I gave. 21 is NAK and 37 is %,
> according to:
>
> <http://www.asciitable.com>

He's using ASCII??

37 is Line Feed,
13 is Carriage Return, and
21 is New Line
in EBCDIC. And, PHP runs on EBCDIC machines.

Better to use '\r' for Carriage Return, and '\n' for Linefeed / Newline, or
PHP defined constant (iirc, $PHP_EOL), and let PHP decide which platform,
which characterset, and which codepoints to use.


Or, better still, use the proper function (in the OP's case, another call to
imagestring() ) to achieve the proper text alignment.

HTH
--
Lew Pitcher
"In Skills, We Trust"
Re: Newline (cr/lf) in imagestring [message #182417 is a reply to message #182408] Sat, 03 August 2013 18:56 Go to previous messageGo to next message
Ed Jay is currently offline  Ed Jay
Messages: 7
Registered: August 2013
Karma: 0
Junior Member
add to buddy list
ignore all messages by this user
Ed Jay wrote:

> I'm merging text into an image using:
>
> $msg = 'string1:' . $string1 . ' string2: ' . $string2;
>
> $text = imagecreatetruecolor($width, $height);
> imagestring($text, 5, 50, 50, $msg, 0x00ff00);
> imagecopymerge($final, $text, 50, 50, 50, 50, $width, $height, 100);
>
> The above works.
>
> What I want to do is have ' string2: ' . $string2 show on a new line. How?
>
> Anything with the quotes displays as a literal, e.g., '\r\n string2'
> outputs as \r\n\string2, as does <br> and anything else, just as the
> manual says it will. I tried adding the string PCP_EOL, but it didn't
> play. I tried $msg = nl2br(string to output) with \r\n within the string,
> but it doesn't play.
>
> So...how do I produce cr/lf?

Thanks for all the replies.

WRT all the suggested strings for cr/lf, none of them seem to play in this
application. For example, using $br = "\r\n" or $br = chr(10).chr(13),
etc., appended as:

$msg = 'string1:' . $string1.$br. ' string2: ' . $string2;

yields only strange characters after string1, then, on the same line
prints string2.

Lew Pitcher's first suggestion works -- make two calls to
imagestring(), with two individual strings..

Thanks all.

--
Ed Jay (remove 'M' to reply by email)

Win the War Against Breast Cancer.
Knowing the facts could save your life.
http://www.breastthermography.info
Re: Newline (cr/lf) in imagestring [message #182418 is a reply to message #182417] Sat, 03 August 2013 21:52 Go to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
On 03/08/13 23:56, Ed Jay wrote:
> Ed Jay wrote:
>
>> I'm merging text into an image using:
>>
>> $msg = 'string1:' . $string1 . ' string2: ' . $string2;
>>
>> $text = imagecreatetruecolor($width, $height);
>> imagestring($text, 5, 50, 50, $msg, 0x00ff00);
>> imagecopymerge($final, $text, 50, 50, 50, 50, $width, $height, 100);
>>
>> The above works.
>>
>> What I want to do is have ' string2: ' . $string2 show on a new line. How?
>>
>> Anything with the quotes displays as a literal, e.g., '\r\n string2'
>> outputs as \r\n\string2, as does <br> and anything else, just as the
>> manual says it will. I tried adding the string PCP_EOL, but it didn't
>> play. I tried $msg = nl2br(string to output) with \r\n within the string,
>> but it doesn't play.
>>
>> So...how do I produce cr/lf?
> Thanks for all the replies.
>
> WRT all the suggested strings for cr/lf, none of them seem to play in this
> application. For example, using $br = "\r\n" or $br = chr(10).chr(13),
> etc., appended as:
>
> $msg = 'string1:' . $string1.$br. ' string2: ' . $string2;
>
> yields only strange characters after string1, then, on the same line
> prints string2.
>
> Lew Pitcher's first suggestion works -- make two calls to
> imagestring(), with two individual strings..

yep. NBasically build your own function that does the formatting.

I had to do that for GD and for PDFlite to flow text into PDF documents.

imagestring is [a] primitive...:LOL

> Thanks all.
>


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Reading a file on same server
Next Topic: ini_get("memory_limit") returns an empty string
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Oct 17 02:13:24 EDT 2017

Total time taken to generate the page: 0.00747 seconds