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

Home » Imported messages » comp.lang.php » Reading & Displaying Latex Rendered images
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Reading & Displaying Latex Rendered images [message #178540] Fri, 29 June 2012 10:24 Go to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
I am developing an application for the university. One basic module/ section of this application is Data Entry. The data is entered using Latex (Latex is a type setting language and is not a WYSIWYG language). The tex software converts the latex code into the required image. For better understanding visit the following link:
http://www.forkosh.com/mathtexpreview.html

You can see that on entering Latex code, the desired output is obtained which is actually an image. This image is produced by the Tex software and is being fetched and displayed on this page. Another way to get that image is as follows:
<img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>

My issue is that I want to get the image generated due to the rendering of the Latex code and then display it after re-sizing and then want store it in the MYSQL database.

As I dont know the name of the image produced due to rendering that's why I can not pick the image with its name. Therefore I tried using function "file_get_contents". Though it returns some garbage values on echo but what next?

I need to know that how can I proceed further or suggest some better way to deal with these issues especially while dealing with LateX rendering. Thanks!
Re: Reading & Displaying Latex Rendered images [message #178541 is a reply to message #178540] Fri, 29 June 2012 11:02 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
Fastian wrote:
> I am developing an application for the university. One basic module/ section of this application is Data Entry. The data is entered using Latex (Latex is a type setting language and is not a WYSIWYG language). The tex software converts the latex code into the required image. For better understanding visit the following link:
> http://www.forkosh.com/mathtexpreview.html
>
> You can see that on entering Latex code, the desired output is obtained which is actually an image. This image is produced by the Tex software and is being fetched and displayed on this page. Another way to get that image is as follows:
> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>
> My issue is that I want to get the image generated due to the rendering of the Latex code and then display it after re-sizing and then want store it in the MYSQL database.
>
> As I dont know the name of the image produced due to rendering that's why I can not pick the image with its name. Therefore I tried using function "file_get_contents". Though it returns some garbage values on echo but what next?
>
> I need to know that how can I proceed further or suggest some better way to deal with these issues especially while dealing with LateX rendering. Thanks!


Can you confirm that:

1/. You are not using or wanting to use PHP to actually render latex
into a bitmap, but that that is being done by this external site and..

2/. the problem therefore is to capture this image and store it and
process it into database and

3/. subsequently display it afterwards?

I can answer those questions, but if they are not the right questions..
I wont bother.



--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Re: Reading & Displaying Latex Rendered images [message #178542 is a reply to message #178541] Fri, 29 June 2012 11:34 Go to previous messageGo to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
On Friday, June 29, 2012 4:02:07 PM UTC+5, The Natural Philosopher wrote:
> Fastian wrote:
>> I am developing an application for the university. One basic module/ section of this application is Data Entry. The data is entered using Latex (Latex is a type setting language and is not a WYSIWYG language). The tex software converts the latex code into the required image. For better understanding visit the following link:
>> http://www.forkosh.com/mathtexpreview.html
>>
>> You can see that on entering Latex code, the desired output is obtained which is actually an image. This image is produced by the Tex software and is being fetched and displayed on this page. Another way to get that image is as follows:
>> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>>
>> My issue is that I want to get the image generated due to the rendering of the Latex code and then display it after re-sizing and then want store it in the MYSQL database.
>>
>> As I dont know the name of the image produced due to rendering that's why I can not pick the image with its name. Therefore I tried using function "file_get_contents". Though it returns some garbage values on echo but what next?
>>
>> I need to know that how can I proceed further or suggest some better way to deal with these issues especially while dealing with LateX rendering. Thanks!
>
>
> Can you confirm that:
>
> 1/. You are not using or wanting to use PHP to actually render latex
> into a bitmap, but that that is being done by this external site and..

Yes. The rendering is being done by mathtex which is actually a cgi script.. The mathtex can be installed on the server and is also available as a web-service on http://www.forkosh.com.
>
> 2/. the problem therefore is to capture this image and store it and
> process it into database and
Yes.
>
> 3/. subsequently display it afterwards?
> Yes.
> I can answer those questions, but if they are not the right questions..
> I wont bother.
>
>
>
> --
> To people who know nothing, anything is possible.
> To people who know too much, it is a sad fact
> that they know how little is really possible -
> and how hard it is to achieve it.
Re: Reading & Displaying Latex Rendered images [message #178543 is a reply to message #178542] Fri, 29 June 2012 12:09 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
Fastian wrote:
> On Friday, June 29, 2012 4:02:07 PM UTC+5, The Natural Philosopher wrote:
>> Fastian wrote:
>>> I am developing an application for the university. One basic module/ section of this application is Data Entry. The data is entered using Latex (Latex is a type setting language and is not a WYSIWYG language). The tex software converts the latex code into the required image. For better understanding visit the following link:
>>> http://www.forkosh.com/mathtexpreview.html
>>>
>>> You can see that on entering Latex code, the desired output is obtained which is actually an image. This image is produced by the Tex software and is being fetched and displayed on this page. Another way to get that image is as follows:
>>> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>>>
>>> My issue is that I want to get the image generated due to the rendering of the Latex code and then display it after re-sizing and then want store it in the MYSQL database.
>>>
>>> As I dont know the name of the image produced due to rendering that's why I can not pick the image with its name. Therefore I tried using function "file_get_contents". Though it returns some garbage values on echo but what next?
>>>
>>> I need to know that how can I proceed further or suggest some better way to deal with these issues especially while dealing with LateX rendering. Thanks!
>>
>> Can you confirm that:
>>
>> 1/. You are not using or wanting to use PHP to actually render latex
>> into a bitmap, but that that is being done by this external site and..
>
> Yes. The rendering is being done by mathtex which is actually a cgi script. The mathtex can be installed on the server and is also available as a web-service on http://www.forkosh.com.
>> 2/. the problem therefore is to capture this image and store it and
>> process it into database and
> Yes.

well, use CURL to get the data, strip the headers from it and then store
the image in a database..


>> 3/. subsequently display it afterwards?
>> Yes.

That is simply a matter of building a php script that will output
minimal headers and the actual image data.

I've got code that does that and resizes too, if needs be.


--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Re: Reading & Displaying Latex Rendered images [message #178547 is a reply to message #178540] Fri, 29 June 2012 13:20 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 6/29/2012 6:24 AM, Fastian wrote:
> I am developing an application for the university. One basic
> module/ section of this application is Data Entry. The data
> is entered using Latex (Latex is a type setting language
> and is not a WYSIWYG language). The tex software converts the
> latex code into the required image. For better understanding
> visit the following link:
> http://www.forkosh.com/mathtexpreview.html
>
> You can see that on entering Latex code, the desired output
> is obtained which is actually an image. This image is produced
> by the Tex software and is being fetched and displayed on this
> page. Another way to get that image is as follows:
> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>
> My issue is that I want to get the image generated due to the
> rendering of the Latex code and then display it after re-sizing
> and then want store it in the MYSQL database.
>
> As I dont know the name of the image produced due to rendering
> that's why I can not pick the image with its name. Therefore I
> tried using function "file_get_contents". Though it returns
> some garbage values on echo but what next?
>
> I need to know that how can I proceed further or suggest some
> better way to deal with these issues especially while dealing
> with LateX rendering. Thanks!
>

You don't show the code you're trying to use, so it's all a guess as to
what's wrong. There are many possibilities.

If you're going to display an image, you need to send it as an image.
My guess is that you're displaying it as text.

Web pages are sent with a content-type of text/html. But if the web
page contains an image, the browser makes a second request to the server
for the image. The image will be sent with a content-type of
image/jpeg, image/gif, etc. So the first thing you need to do is ensure
you are sending the correct header when displaying it (in this case it
should be image/gif) (obviously this needs to be done in a separate
script from the rest of the page and accessed with an <img= tag).

So what you could do is in your test page, put something like:

<img src="testimg.php" ....>

Then in your testimg.php file, fetch the file with file_get_contents
then display it with the correct headers, i.e.

header ('Content-type: image/gif');

Of course, if this is the only thing on your test page (it's sending
NOTHING else), you can skip the <img= ...> tag and just send the correct
content-type at the start of your script.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Reading & Displaying Latex Rendered images [message #178556 is a reply to message #178547] Mon, 02 July 2012 06:42 Go to previous messageGo to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
On Friday, June 29, 2012 6:20:45 PM UTC+5, Jerry Stuckle wrote:
> On 6/29/2012 6:24 AM, Fastian wrote:
>> I am developing an application for the university. One basic
>> module/ section of this application is Data Entry. The data
>> is entered using Latex (Latex is a type setting language
>> and is not a WYSIWYG language). The tex software converts the
>> latex code into the required image. For better understanding
>> visit the following link:
>> http://www.forkosh.com/mathtexpreview.html
>>
>> You can see that on entering Latex code, the desired output
>> is obtained which is actually an image. This image is produced
>> by the Tex software and is being fetched and displayed on this
>> page. Another way to get that image is as follows:
>> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>>
>> My issue is that I want to get the image generated due to the
>> rendering of the Latex code and then display it after re-sizing
>> and then want store it in the MYSQL database.
>>
>> As I dont know the name of the image produced due to rendering
>> that's why I can not pick the image with its name. Therefore I
>> tried using function "file_get_contents". Though it returns
>> some garbage values on echo but what next?
>>
>> I need to know that how can I proceed further or suggest some
>> better way to deal with these issues especially while dealing
>> with LateX rendering. Thanks!
>>
>
> You don't show the code you're trying to use, so it's all a guess as to
> what's wrong. There are many possibilities.
>
> If you're going to display an image, you need to send it as an image.
> My guess is that you're displaying it as text.
>
> Web pages are sent with a content-type of text/html. But if the web
> page contains an image, the browser makes a second request to the server
> for the image. The image will be sent with a content-type of
> image/jpeg, image/gif, etc. So the first thing you need to do is ensure
> you are sending the correct header when displaying it (in this case it
> should be image/gif) (obviously this needs to be done in a separate
> script from the rest of the page and accessed with an <img= tag).
>
> So what you could do is in your test page, put something like:
>
> <img src="testimg.php" ....>
>
> Then in your testimg.php file, fetch the file with file_get_contents
> then display it with the correct headers, i.e.
>
> header ('Content-type: image/gif');
>
> Of course, if this is the only thing on your test page (it's sending
> NOTHING else), you can skip the <img= ...> tag and just send the correct
> content-type at the start of your script.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex(at)attglobal(dot)net
> ==================

Pls have a look on the code:
As you suggested my testing.php file code is as follows:

<?
$image = file_get_contents('users.gif');

header('Content-Type: image/gif');

//imagegif($image); // I also tried to display image with imagegif but it also didnt work.

?>
The code of getimage.php file is as follows:
<html>
<img src="testing.php">
</html>

But the image is NOT displayed on the browser.Where I am wrong?
Both php files and image (users.gif) is present in the same directory.
I have also noticed that <img src= ""> do not work on the page where you have used header('Content-Type: image/gif'); ......... why?
Re: Reading & Displaying Latex Rendered images [message #178557 is a reply to message #178556] Mon, 02 July 2012 07:34 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 02/07/2012 8:42, Fastian escribió/wrote:
> <?
> $image = file_get_contents('users.gif');
>
> header('Content-Type: image/gif');
>
> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.

The imagegif() function [1] expects «An image resource, returned by one
of the image creation functions, such as imagecreatetruecolor()». I
don't know how you reached the conclusion that you need such functions,
given that are not even using PHP to generate the image :-?

Probably, readfile() is all you need.


[1] http://php.net/imagegif
[1] http://php.net/readfile

> But the image is NOT displayed on the browser.Where I am wrong?

Browsers are basically designed to ignore invalid stuff and your
"testing.php" script is possibly printing an error message rather than a
valid GIF file. I suggest you remove the last layer and debug
"testing.php" directly.




--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Reading & Displaying Latex Rendered images [message #178559 is a reply to message #178540] Mon, 02 July 2012 07:28 Go to previous messageGo to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
On Friday, June 29, 2012 3:24:13 PM UTC+5, Fastian wrote:
> I am developing an application for the university. One basic module/ section of this application is Data Entry. The data is entered using Latex (Latex is a type setting language and is not a WYSIWYG language). The tex software converts the latex code into the required image. For better understanding visit the following link:
> http://www.forkosh.com/mathtexpreview.html
>
> You can see that on entering Latex code, the desired output is obtained which is actually an image. This image is produced by the Tex software and is being fetched and displayed on this page. Another way to get that image is as follows:
> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>
> My issue is that I want to get the image generated due to the rendering of the Latex code and then display it after re-sizing and then want store it in the MYSQL database.
>
> As I dont know the name of the image produced due to rendering that's why I can not pick the image with its name. Therefore I tried using function "file_get_contents". Though it returns some garbage values on echo but what next?
>
> I need to know that how can I proceed further or suggest some better way to deal with these issues especially while dealing with LateX rendering. Thanks!

___________________________________________________________________________ _____I am writing this post to explain my project so that you may give me more relevant suggestions:

I have to develop an application that will help us develop a database of questions. These questions will be used for developing tests/ exams. Latex is required to enter scientific and mathematical text. As Latex is not WYSIWYG therefore the data entry person will like to see the output for the latex text. For that my latex code will be rendered and then I will be able to get the
desired output. As my application is web based therefore I think I can use MathTeX. (suggest me anyother better option if you know especially if available in Windows platform) So first thing to deal with is to get the rendered images and display them in desired format. The required format is a question with multiple options (MCQ). In short I need a preview of my question and answer options.
The second issue is that I need to get ONE image which should have question with its options and both should be transformed/ merged in such a way that ultimately one image is obtained from the input(question and options). The requirement of my application is that this complete question should then be saved in the database.

I can get the input for question and options in textarea. Now I need to show the preview as well as transform them into one image so as to store in the database.

Guide me which PHP functions will help me in reading and displaying the images as well as merging the images etc. Any suggestion that can help me in this project will highly be appreciated. Thanks!
Re: Reading & Displaying Latex Rendered images [message #178560 is a reply to message #178557] Mon, 02 July 2012 08:10 Go to previous messageGo to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
On Monday, July 2, 2012 12:34:33 PM UTC+5, Álvaro G. Vicario wrote:
> El 02/07/2012 8:42, Fastian escribió/wrote:
>> <?
>> $image = file_get_contents('users.gif');
>>
>> header('Content-Type: image/gif');
>>
>> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.
>
> The imagegif() function [1] expects «An image resource, returned by one
> of the image creation functions, such as imagecreatetruecolor()». I
> don't know how you reached the conclusion that you need such functions,
> given that are not even using PHP to generate the image :-?
>
> Probably, readfile() is all you need.
>
>
> [1] http://php.net/imagegif
> [1] http://php.net/readfile
>
>> But the image is NOT displayed on the browser.Where I am wrong?
>
> Browsers are basically designed to ignore invalid stuff and your
> "testing.php" script is possibly printing an error message rather than a
> valid GIF file. I suggest you remove the last layer and debug
> "testing.php" directly.
>
>
>
>
> --
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web: http://borrame.com
> -- Mi web de humor satinado: http://www.demogracia.com
> --



On Monday, July 2, 2012 12:34:33 PM UTC+5, Álvaro G. Vicario wrote:
> El 02/07/2012 8:42, Fastian escribió/wrote:
>> <?
>> $image = file_get_contents('users.gif');
>>
>> header('Content-Type: image/gif');
>>
>> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.
>
> The imagegif() function [1] expects «An image resource, returned by one
> of the image creation functions, such as imagecreatetruecolor()». I
> don't know how you reached the conclusion that you need such functions,
> given that are not even using PHP to generate the image :-?
>
> Probably, readfile() is all you need.
>
>
> [1] http://php.net/imagegif
> [1] http://php.net/readfile
>
>> But the image is NOT displayed on the browser.Where I am wrong?
>
> Browsers are basically designed to ignore invalid stuff and your
> "testing.php" script is possibly printing an error message rather than a
> valid GIF file. I suggest you remove the last layer and debug
> "testing.php" directly.
>
>
>
>
> --
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web: http://borrame.com
> -- Mi web de humor satinado: http://www.demogracia.com
> --



On Monday, July 2, 2012 12:34:33 PM UTC+5, Álvaro G. Vicario wrote:
> El 02/07/2012 8:42, Fastian escribió/wrote:
>> <?
>> $image = file_get_contents('users.gif');
>>
>> header('Content-Type: image/gif');
>>
>> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.
>
> The imagegif() function [1] expects «An image resource, returned by one
> of the image creation functions, such as imagecreatetruecolor()». I
> don't know how you reached the conclusion that you need such functions,
> given that are not even using PHP to generate the image :-?
>
> Probably, readfile() is all you need.
>
>
> [1] http://php.net/imagegif
> [1] http://php.net/readfile
>
>> But the image is NOT displayed on the browser.Where I am wrong?
>
> Browsers are basically designed to ignore invalid stuff and your
> "testing.php" script is possibly printing an error message rather than a
> valid GIF file. I suggest you remove the last layer and debug
> "testing.php" directly.
>
>
>
>
> --
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web: http://borrame.com
> -- Mi web de humor satinado: http://www.demogracia.com
> --



On Monday, July 2, 2012 12:34:33 PM UTC+5, Álvaro G. Vicario wrote:
> El 02/07/2012 8:42, Fastian escribió/wrote:
>> <?
>> $image = file_get_contents('users.gif');
>>
>> header('Content-Type: image/gif');
>>
>> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.
>
> The imagegif() function [1] expects «An image resource, returned by one
> of the image creation functions, such as imagecreatetruecolor()». I
> don't know how you reached the conclusion that you need such functions,
> given that are not even using PHP to generate the image :-?
>
> Probably, readfile() is all you need.
>
>
> [1] http://php.net/imagegif
> [1] http://php.net/readfile
>
>> But the image is NOT displayed on the browser.Where I am wrong?
>
> Browsers are basically designed to ignore invalid stuff and your
> "testing.php" script is possibly printing an error message rather than a
> valid GIF file. I suggest you remove the last layer and debug
> "testing.php" directly.
>
>
>
>
> --
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web: http://borrame.com
> -- Mi web de humor satinado: http://www.demogracia.com
> --

I think readfile is useful when you know the name of the image so that you can access it with its name. In my case the I am trying to use file_get_contents function only because I am not aware of the name of the image file that will result from rendering. Have a look here: http://www.forkosh.com/mathtex.html OR view source of http://www.forkosh.com/mathtexpreview.html.
I thought that without knowing the name of the image you can still get the image output using file_get_contents function. Tell me if it possible to use readfile or with anyother function.
Re: Reading & Displaying Latex Rendered images [message #178561 is a reply to message #178559] Mon, 02 July 2012 08:44 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 02/07/2012 9:28, Fastian escribió/wrote:
> ___________________________________________________________________________ _____I
> am writing this post to explain my project so that you may give me
> more relevant suggestions:
>
> I have to develop an application that will help us develop a database
> of questions. These questions will be used for developing tests/
> exams. Latex is required to enter scientific and mathematical text.
[...]
> Guide me which PHP functions will help me in reading and displaying
> the images as well as merging the images etc. Any suggestion that can
> help me in this project will highly be appreciated. Thanks!

Alright, I think I finally got what your problem is. Your picture's URL
is by no means unknown. The URL is always this:

http://www.forkosh.com/mathtex.cgi?formdata=blah

.... where formadata is a GET parameter that contains the raw LaTeX code.
You can compose the actual URL with rawurlencode(). E.g.:

$latex = '\Large f(x)=\int_{-\infty}^x e^{-t^2}dt';
$url = 'http://www.forkosh.com/mathtex.cgi?formdata=' .
rawurlencode($latex);

Once you have the URL, you could download it with many PHP functions,
including the ones you've been evaluating, but you don't really need to.
You just have to use the <img> tag in an HTML document and the browser
will download it for you:

<img src="<?php echo htmlspecialchars($url); ?>">


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Reading & Displaying Latex Rendered images [message #178562 is a reply to message #178561] Mon, 02 July 2012 09:54 Go to previous messageGo to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
On Monday, July 2, 2012 1:44:28 PM UTC+5, Álvaro G. Vicario wrote:
> El 02/07/2012 9:28, Fastian escribió/wrote:
>> ___________________________________________________________________________ _____I
>> am writing this post to explain my project so that you may give me
>> more relevant suggestions:
>>
>> I have to develop an application that will help us develop a database
>> of questions. These questions will be used for developing tests/
>> exams. Latex is required to enter scientific and mathematical text.
> [...]
>> Guide me which PHP functions will help me in reading and displaying
>> the images as well as merging the images etc. Any suggestion that can
>> help me in this project will highly be appreciated. Thanks!
>
> Alright, I think I finally got what your problem is. Your picture's URL
> is by no means unknown. The URL is always this:
>
> http://www.forkosh.com/mathtex.cgi?formdata=blah
>
> ... where formadata is a GET parameter that contains the raw LaTeX code.
> You can compose the actual URL with rawurlencode(). E.g.:
>
> $latex = '\Large f(x)=\int_{-\infty}^x e^{-t^2}dt';
> $url = 'http://www.forkosh.com/mathtex.cgi?formdata=' .
> rawurlencode($latex);
>
> Once you have the URL, you could download it with many PHP functions,
> including the ones you've been evaluating, but you don't really need to.
> You just have to use the <img> tag in an HTML document and the browser
> will download it for you:
>
> <img src="<?php echo htmlspecialchars($url); ?>">
>
>
> --
> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
> -- Mi sitio sobre programación web: http://borrame.com
> -- Mi web de humor satinado: http://www.demogracia.com
> --

Done! Thanks for help.
Now I come to the second step of my project that I explained in my second last post in detail that I need to take the question and different options from the user. Then I need to combine/ merge them together in a format of a Multiple Choice Question(MCQ) and display this MCQ on the webpage. As well as I need to store the complete image(MCQ) in the database.
What do you suggest, should I utilize all the input in one go(question + options) and try to bring them in one variable (using some formatting commands/ operators of Latex) and send them for rendering. In this way I hope to get one image for the complete question. (will it be possible and whether Latex help me to format the input to get the desired formatted output)
OR should i take all the inputs as images separately; question separately and all other options separately. Then I merge them to get the desired format of question.
Also mention the appropriate functions or examples if possible.
Re: Reading & Displaying Latex Rendered images [message #178563 is a reply to message #178562] Mon, 02 July 2012 10:46 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/2/2012 5:54 AM, Fastian wrote:
> On Monday, July 2, 2012 1:44:28 PM UTC+5, Álvaro G. Vicario wrote:
>> El 02/07/2012 9:28, Fastian escribió/wrote:
>>> ___________________________________________________________________________ _____I
>>> am writing this post to explain my project so that you may give me
>>> more relevant suggestions:
>>>
>>> I have to develop an application that will help us develop a database
>>> of questions. These questions will be used for developing tests/
>>> exams. Latex is required to enter scientific and mathematical text.
>> [...]
>>> Guide me which PHP functions will help me in reading and displaying
>>> the images as well as merging the images etc. Any suggestion that can
>>> help me in this project will highly be appreciated. Thanks!
>>
>> Alright, I think I finally got what your problem is. Your picture's URL
>> is by no means unknown. The URL is always this:
>>
>> http://www.forkosh.com/mathtex.cgi?formdata=blah
>>
>> ... where formadata is a GET parameter that contains the raw LaTeX code.
>> You can compose the actual URL with rawurlencode(). E.g.:
>>
>> $latex = '\Large f(x)=\int_{-\infty}^x e^{-t^2}dt';
>> $url = 'http://www.forkosh.com/mathtex.cgi?formdata=' .
>> rawurlencode($latex);
>>
>> Once you have the URL, you could download it with many PHP functions,
>> including the ones you've been evaluating, but you don't really need to.
>> You just have to use the <img> tag in an HTML document and the browser
>> will download it for you:
>>
>> <img src="<?php echo htmlspecialchars($url); ?>">
>>
>>
>> --
>> -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
>> -- Mi sitio sobre programación web: http://borrame.com
>> -- Mi web de humor satinado: http://www.demogracia.com
>> --
>
> Done! Thanks for help.
> Now I come to the second step of my project that I explained in my second last post in detail that I need to take the question and different options from the user. Then I need to combine/ merge them together in a format of a Multiple Choice Question(MCQ) and display this MCQ on the webpage. As well as I need to store the complete image(MCQ) in the database.
> What do you suggest, should I utilize all the input in one go(question + options) and try to bring them in one variable (using some formatting commands/ operators of Latex) and send them for rendering. In this way I hope to get one image for the complete question. (will it be possible and whether Latex help me to format the input to get the desired formatted output)
> OR should i take all the inputs as images separately; question separately and all other options separately. Then I merge them to get the desired format of question.
> Also mention the appropriate functions or examples if possible.
>

I would not put everything in one image. Rather, have the question,
followed by a list of radio buttons, one answer per radio button. If
the question or result needs to be an image, then make it an image.
Otherwise, use plain text (images are much bigger than characters for
the same text).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Reading & Displaying Latex Rendered images [message #178564 is a reply to message #178556] Mon, 02 July 2012 10:53 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/2/2012 2:42 AM, Fastian wrote:
> On Friday, June 29, 2012 6:20:45 PM UTC+5, Jerry Stuckle wrote:
>> On 6/29/2012 6:24 AM, Fastian wrote:
>>> I am developing an application for the university. One basic
>>> module/ section of this application is Data Entry. The data
>>> is entered using Latex (Latex is a type setting language
>>> and is not a WYSIWYG language). The tex software converts the
>>> latex code into the required image. For better understanding
>>> visit the following link:
>>> http://www.forkosh.com/mathtexpreview.html
>>>
>>> You can see that on entering Latex code, the desired output
>>> is obtained which is actually an image. This image is produced
>>> by the Tex software and is being fetched and displayed on this
>>> page. Another way to get that image is as follows:
>>> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>>>
>>> My issue is that I want to get the image generated due to the
>>> rendering of the Latex code and then display it after re-sizing
>>> and then want store it in the MYSQL database.
>>>
>>> As I dont know the name of the image produced due to rendering
>>> that's why I can not pick the image with its name. Therefore I
>>> tried using function "file_get_contents". Though it returns
>>> some garbage values on echo but what next?
>>>
>>> I need to know that how can I proceed further or suggest some
>>> better way to deal with these issues especially while dealing
>>> with LateX rendering. Thanks!
>>>
>>
>> You don't show the code you're trying to use, so it's all a guess as to
>> what's wrong. There are many possibilities.
>>
>> If you're going to display an image, you need to send it as an image.
>> My guess is that you're displaying it as text.
>>
>> Web pages are sent with a content-type of text/html. But if the web
>> page contains an image, the browser makes a second request to the server
>> for the image. The image will be sent with a content-type of
>> image/jpeg, image/gif, etc. So the first thing you need to do is ensure
>> you are sending the correct header when displaying it (in this case it
>> should be image/gif) (obviously this needs to be done in a separate
>> script from the rest of the page and accessed with an <img= tag).
>>
>> So what you could do is in your test page, put something like:
>>
>> <img src="testimg.php" ....>
>>
>> Then in your testimg.php file, fetch the file with file_get_contents
>> then display it with the correct headers, i.e.
>>
>> header ('Content-type: image/gif');
>>
>> Of course, if this is the only thing on your test page (it's sending
>> NOTHING else), you can skip the <img= ...> tag and just send the correct
>> content-type at the start of your script.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstucklex(at)attglobal(dot)net
>> ==================
>
> Pls have a look on the code:
> As you suggested my testing.php file code is as follows:
>
> <?
> $image = file_get_contents('users.gif');
>
> header('Content-Type: image/gif');
>
> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.
>
> ?>
> The code of getimage.php file is as follows:
> <html>
> <img src="testing.php">
> </html>
>
> But the image is NOT displayed on the browser.Where I am wrong?
> Both php files and image (users.gif) is present in the same directory.
> I have also noticed that <img src= ""> do not work on the page where you have used header('Content-Type: image/gif'); ......... why?
>

Where are you outputting the image? file_get_contents() does not output
anything.

And no, <img src=..."> is an html command, and valid in pages with
content-type of text/html.

I think your first problem is not understanding how html works. A
response has one content-type. A typical web page will have a
content-type of text/html, and will contain html code. <img src=...> is
an html command.

Tags like <img src=...> (and many others) will cause an additional
request to be made to the server. If the content-type of the response
is image/gif, then the browser will only process it as an image. If it
is not a valid image, the browser will ignore it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Reading & Displaying Latex Rendered images [message #178565 is a reply to message #178564] Mon, 02 July 2012 11:24 Go to previous messageGo to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
On Monday, July 2, 2012 3:53:13 PM UTC+5, Jerry Stuckle wrote:
> On 7/2/2012 2:42 AM, Fastian wrote:
>> On Friday, June 29, 2012 6:20:45 PM UTC+5, Jerry Stuckle wrote:
>>> On 6/29/2012 6:24 AM, Fastian wrote:
>>>> I am developing an application for the university. One basic
>>>> module/ section of this application is Data Entry. The data
>>>> is entered using Latex (Latex is a type setting language
>>>> and is not a WYSIWYG language). The tex software converts the
>>>> latex code into the required image. For better understanding
>>>> visit the following link:
>>>> http://www.forkosh.com/mathtexpreview.html
>>>>
>>>> You can see that on entering Latex code, the desired output
>>>> is obtained which is actually an image. This image is produced
>>>> by the Tex software and is being fetched and displayed on this
>>>> page. Another way to get that image is as follows:
>>>> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>>>>
>>>> My issue is that I want to get the image generated due to the
>>>> rendering of the Latex code and then display it after re-sizing
>>>> and then want store it in the MYSQL database.
>>>>
>>>> As I dont know the name of the image produced due to rendering
>>>> that's why I can not pick the image with its name. Therefore I
>>>> tried using function "file_get_contents". Though it returns
>>>> some garbage values on echo but what next?
>>>>
>>>> I need to know that how can I proceed further or suggest some
>>>> better way to deal with these issues especially while dealing
>>>> with LateX rendering. Thanks!
>>>>
>>>
>>> You don't show the code you're trying to use, so it's all a guess as to
>>> what's wrong. There are many possibilities.
>>>
>>> If you're going to display an image, you need to send it as an image.
>>> My guess is that you're displaying it as text.
>>>
>>> Web pages are sent with a content-type of text/html. But if the web
>>> page contains an image, the browser makes a second request to the server
>>> for the image. The image will be sent with a content-type of
>>> image/jpeg, image/gif, etc. So the first thing you need to do is ensure
>>> you are sending the correct header when displaying it (in this case it
>>> should be image/gif) (obviously this needs to be done in a separate
>>> script from the rest of the page and accessed with an <img= tag).
>>>
>>> So what you could do is in your test page, put something like:
>>>
>>> <img src="testimg.php" ....>
>>>
>>> Then in your testimg.php file, fetch the file with file_get_contents
>>> then display it with the correct headers, i.e.
>>>
>>> header ('Content-type: image/gif');
>>>
>>> Of course, if this is the only thing on your test page (it's sending
>>> NOTHING else), you can skip the <img= ...> tag and just send the correct
>>> content-type at the start of your script.
>>>
>>> --
>>> ==================
>>> Remove the "x" from my email address
>>> Jerry Stuckle
>>> JDS Computer Training Corp.
>>> jstucklex(at)attglobal(dot)net
>>> ==================
>>
>> Pls have a look on the code:
>> As you suggested my testing.php file code is as follows:
>>
>> <?
>> $image = file_get_contents('users.gif');
>>
>> header('Content-Type: image/gif');
>>
>> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.
>>
>> ?>
>> The code of getimage.php file is as follows:
>> <html>
>> <img src="testing.php">
>> </html>
>>
>> But the image is NOT displayed on the browser.Where I am wrong?
>> Both php files and image (users.gif) is present in the same directory.
>> I have also noticed that <img src= ""> do not work on the page where you have used header('Content-Type: image/gif'); ......... why?
>>
>
> Where are you outputting the image? file_get_contents() does not output
> anything.
>
> And no, <img src=..."> is an html command, and valid in pages with
> content-type of text/html.
>
> I think your first problem is not understanding how html works. A
> response has one content-type. A typical web page will have a
> content-type of text/html, and will contain html code. <img src=...> is
> an html command.
>
> Tags like <img src=...> (and many others) will cause an additional
> request to be made to the server. If the content-type of the response
> is image/gif, then the browser will only process it as an image. If it
> is not a valid image, the browser will ignore it.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex(at)attglobal(dot)net
> ==================

Ok. I got your point. But as it is the requirement of my project to store the complete question as an image in addition to storing latex text. Therefore I need to process the images (both question + options) and have to make them
transform into a complete question.
Therefore I thought that file_get_contents() may be helpful in this case as it then enable me to use imagecopy () and other functions. what you say?
Re: Reading & Displaying Latex Rendered images [message #178567 is a reply to message #178565] Mon, 02 July 2012 13:35 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/2/2012 7:24 AM, Fastian wrote:
> On Monday, July 2, 2012 3:53:13 PM UTC+5, Jerry Stuckle wrote:
>> On 7/2/2012 2:42 AM, Fastian wrote:
>>> On Friday, June 29, 2012 6:20:45 PM UTC+5, Jerry Stuckle wrote:
>>>> On 6/29/2012 6:24 AM, Fastian wrote:
>>>> > I am developing an application for the university. One basic
>>>> > module/ section of this application is Data Entry. The data
>>>> > is entered using Latex (Latex is a type setting language
>>>> > and is not a WYSIWYG language). The tex software converts the
>>>> > latex code into the required image. For better understanding
>>>> > visit the following link:
>>>> > http://www.forkosh.com/mathtexpreview.html
>>>> >
>>>> > You can see that on entering Latex code, the desired output
>>>> > is obtained which is actually an image. This image is produced
>>>> > by the Tex software and is being fetched and displayed on this
>>>> > page. Another way to get that image is as follows:
>>>> > <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt="" border=0 align=middle>
>>>> >
>>>> > My issue is that I want to get the image generated due to the
>>>> > rendering of the Latex code and then display it after re-sizing
>>>> > and then want store it in the MYSQL database.
>>>> >
>>>> > As I dont know the name of the image produced due to rendering
>>>> > that's why I can not pick the image with its name. Therefore I
>>>> > tried using function "file_get_contents". Though it returns
>>>> > some garbage values on echo but what next?
>>>> >
>>>> > I need to know that how can I proceed further or suggest some
>>>> > better way to deal with these issues especially while dealing
>>>> > with LateX rendering. Thanks!
>>>> >
>>>>
>>>> You don't show the code you're trying to use, so it's all a guess as to
>>>> what's wrong. There are many possibilities.
>>>>
>>>> If you're going to display an image, you need to send it as an image.
>>>> My guess is that you're displaying it as text.
>>>>
>>>> Web pages are sent with a content-type of text/html. But if the web
>>>> page contains an image, the browser makes a second request to the server
>>>> for the image. The image will be sent with a content-type of
>>>> image/jpeg, image/gif, etc. So the first thing you need to do is ensure
>>>> you are sending the correct header when displaying it (in this case it
>>>> should be image/gif) (obviously this needs to be done in a separate
>>>> script from the rest of the page and accessed with an <img= tag).
>>>>
>>>> So what you could do is in your test page, put something like:
>>>>
>>>> <img src="testimg.php" ....>
>>>>
>>>> Then in your testimg.php file, fetch the file with file_get_contents
>>>> then display it with the correct headers, i.e.
>>>>
>>>> header ('Content-type: image/gif');
>>>>
>>>> Of course, if this is the only thing on your test page (it's sending
>>>> NOTHING else), you can skip the <img= ...> tag and just send the correct
>>>> content-type at the start of your script.
>>>>
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstucklex(at)attglobal(dot)net
>>>> ==================
>>>
>>> Pls have a look on the code:
>>> As you suggested my testing.php file code is as follows:
>>>
>>> <?
>>> $image = file_get_contents('users.gif');
>>>
>>> header('Content-Type: image/gif');
>>>
>>> //imagegif($image); // I also tried to display image with imagegif but it also didnt work.
>>>
>>> ?>
>>> The code of getimage.php file is as follows:
>>> <html>
>>> <img src="testing.php">
>>> </html>
>>>
>>> But the image is NOT displayed on the browser.Where I am wrong?
>>> Both php files and image (users.gif) is present in the same directory.
>>> I have also noticed that <img src= ""> do not work on the page where you have used header('Content-Type: image/gif'); ......... why?
>>>
>>
>> Where are you outputting the image? file_get_contents() does not output
>> anything.
>>
>> And no, <img src=..."> is an html command, and valid in pages with
>> content-type of text/html.
>>
>> I think your first problem is not understanding how html works. A
>> response has one content-type. A typical web page will have a
>> content-type of text/html, and will contain html code. <img src=...> is
>> an html command.
>>
>> Tags like <img src=...> (and many others) will cause an additional
>> request to be made to the server. If the content-type of the response
>> is image/gif, then the browser will only process it as an image. If it
>> is not a valid image, the browser will ignore it.
>>
>
> Ok. I got your point. But as it is the requirement of my project to store
> the complete question as an image in addition to storing latex text.
> Therefore I need to process the images (both question + options) and
> have to make them transform into a complete question.
> Therefore I thought that file_get_contents() may be helpful in this
> case as it then enable me to use imagecopy () and other functions.
> what you say?
>

Why would a customer care whether the question is stored as a single
image or separate entries? In over 40 years of programming I've never
had such a requirement in a project. I admit I've had some stupid
requirements in the past - but I've always been able to convince the
customer why it should not be done that way. All part of being a
successful consultant.

I would go back to the customer and explaining why it is a bad idea and
convince the customer to change the requirement.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Reading & Displaying Latex Rendered images [message #178569 is a reply to message #178567] Mon, 02 July 2012 13:41 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/2/2012 9:35 AM, Jerry Stuckle wrote:
> On 7/2/2012 7:24 AM, Fastian wrote:
>> On Monday, July 2, 2012 3:53:13 PM UTC+5, Jerry Stuckle wrote:
>>> On 7/2/2012 2:42 AM, Fastian wrote:
>>>> On Friday, June 29, 2012 6:20:45 PM UTC+5, Jerry Stuckle wrote:
>>>> > On 6/29/2012 6:24 AM, Fastian wrote:
>>>> >> I am developing an application for the university. One basic
>>>> > > module/ section of this application is Data Entry. The data
>>>> > > is entered using Latex (Latex is a type setting language
>>>> > > and is not a WYSIWYG language). The tex software converts the
>>>> > > latex code into the required image. For better understanding
>>>> > > visit the following link:
>>>> >> http://www.forkosh.com/mathtexpreview.html
>>>> >>
>>>> >> You can see that on entering Latex code, the desired output
>>>> > > is obtained which is actually an image. This image is produced
>>>> > > by the Tex software and is being fetched and displayed on this
>>>> > > page. Another way to get that image is as follows:
>>>> >> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt=""
>>>> >> border=0 align=middle>
>>>> >>
>>>> >> My issue is that I want to get the image generated due to the
>>>> > > rendering of the Latex code and then display it after re-sizing
>>>> > > and then want store it in the MYSQL database.
>>>> >>
>>>> >> As I dont know the name of the image produced due to rendering
>>>> > > that's why I can not pick the image with its name. Therefore I
>>>> > > tried using function "file_get_contents". Though it returns
>>>> >> some garbage values on echo but what next?
>>>> >>
>>>> >> I need to know that how can I proceed further or suggest some
>>>> > > better way to deal with these issues especially while dealing
>>>> > > with LateX rendering. Thanks!
>>>> >>
>>>> >
>>>> > You don't show the code you're trying to use, so it's all a guess
>>>> > as to
>>>> > what's wrong. There are many possibilities.
>>>> >
>>>> > If you're going to display an image, you need to send it as an image.
>>>> > My guess is that you're displaying it as text.
>>>> >
>>>> > Web pages are sent with a content-type of text/html. But if the web
>>>> > page contains an image, the browser makes a second request to the
>>>> > server
>>>> > for the image. The image will be sent with a content-type of
>>>> > image/jpeg, image/gif, etc. So the first thing you need to do is
>>>> > ensure
>>>> > you are sending the correct header when displaying it (in this case it
>>>> > should be image/gif) (obviously this needs to be done in a separate
>>>> > script from the rest of the page and accessed with an <img= tag).
>>>> >
>>>> > So what you could do is in your test page, put something like:
>>>> >
>>>> > <img src="testimg.php" ....>
>>>> >
>>>> > Then in your testimg.php file, fetch the file with file_get_contents
>>>> > then display it with the correct headers, i.e.
>>>> >
>>>> > header ('Content-type: image/gif');
>>>> >
>>>> > Of course, if this is the only thing on your test page (it's sending
>>>> > NOTHING else), you can skip the <img= ...> tag and just send the
>>>> > correct
>>>> > content-type at the start of your script.
>>>> >
>>>> > --
>>>> > ==================
>>>> > Remove the "x" from my email address
>>>> > Jerry Stuckle
>>>> > JDS Computer Training Corp.
>>>> > jstucklex(at)attglobal(dot)net
>>>> > ==================
>>>>
>>>> Pls have a look on the code:
>>>> As you suggested my testing.php file code is as follows:
>>>>
>>>> <?
>>>> $image = file_get_contents('users.gif');
>>>>
>>>> header('Content-Type: image/gif');
>>>>
>>>> //imagegif($image); // I also tried to display image with imagegif
>>>> but it also didnt work.
>>>>
>>>> ?>
>>>> The code of getimage.php file is as follows:
>>>> <html>
>>>> <img src="testing.php">
>>>> </html>
>>>>
>>>> But the image is NOT displayed on the browser.Where I am wrong?
>>>> Both php files and image (users.gif) is present in the same directory.
>>>> I have also noticed that <img src= ""> do not work on the page where
>>>> you have used header('Content-Type: image/gif'); ......... why?
>>>>
>>>
>>> Where are you outputting the image? file_get_contents() does not output
>>> anything.
>>>
>>> And no, <img src=..."> is an html command, and valid in pages with
>>> content-type of text/html.
>>>
>>> I think your first problem is not understanding how html works. A
>>> response has one content-type. A typical web page will have a
>>> content-type of text/html, and will contain html code. <img src=...> is
>>> an html command.
>>>
>>> Tags like <img src=...> (and many others) will cause an additional
>>> request to be made to the server. If the content-type of the response
>>> is image/gif, then the browser will only process it as an image. If it
>>> is not a valid image, the browser will ignore it.
>>>
>>
>> Ok. I got your point. But as it is the requirement of my project to store
>> the complete question as an image in addition to storing latex text.
>> Therefore I need to process the images (both question + options) and
>> have to make them transform into a complete question.
>> Therefore I thought that file_get_contents() may be helpful in this
>> case as it then enable me to use imagecopy () and other functions.
>> what you say?
>>
>
> Why would a customer care whether the question is stored as a single
> image or separate entries? In over 40 years of programming I've never
> had such a requirement in a project. I admit I've had some stupid
> requirements in the past - but I've always been able to convince the
> customer why it should not be done that way. All part of being a
> successful consultant.
>
> I would go back to the customer and explaining why it is a bad idea and
> convince the customer to change the requirement.
>

To clarify: by stupid requirement I mean having to put the question and
all the answers together into one image.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Reading & Displaying Latex Rendered images [message #178572 is a reply to message #178569] Mon, 02 July 2012 17:00 Go to previous messageGo to next message
Fastian is currently offline  Fastian
Messages: 20
Registered: June 2012
Karma: 0
Junior Member
On Monday, July 2, 2012 6:41:03 PM UTC+5, Jerry Stuckle wrote:
> On 7/2/2012 9:35 AM, Jerry Stuckle wrote:
>> On 7/2/2012 7:24 AM, Fastian wrote:
>>> On Monday, July 2, 2012 3:53:13 PM UTC+5, Jerry Stuckle wrote:
>>>> On 7/2/2012 2:42 AM, Fastian wrote:
>>>> > On Friday, June 29, 2012 6:20:45 PM UTC+5, Jerry Stuckle wrote:
>>>> >> On 6/29/2012 6:24 AM, Fastian wrote:
>>>> >>> I am developing an application for the university. One basic
>>>> >> > module/ section of this application is Data Entry. The data
>>>> >> > is entered using Latex (Latex is a type setting language
>>>> >> > and is not a WYSIWYG language). The tex software converts the
>>>> >> > latex code into the required image. For better understanding
>>>> >> > visit the following link:
>>>> >>> http://www.forkosh.com/mathtexpreview.html
>>>> >>>
>>>> >>> You can see that on entering Latex code, the desired output
>>>> >> > is obtained which is actually an image. This image is produced
>>>> >> > by the Tex software and is being fetched and displayed on this
>>>> >> > page. Another way to get that image is as follows:
>>>> >>> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt=""
>>>> >>> border=0 align=middle>
>>>> >>>
>>>> >>> My issue is that I want to get the image generated due to the
>>>> >> > rendering of the Latex code and then display it after re-sizing
>>>> >> > and then want store it in the MYSQL database.
>>>> >>>
>>>> >>> As I dont know the name of the image produced due to rendering
>>>> >> > that's why I can not pick the image with its name. Therefore I
>>>> >> > tried using function "file_get_contents". Though it returns
>>>> >>> some garbage values on echo but what next?
>>>> >>>
>>>> >>> I need to know that how can I proceed further or suggest some
>>>> >> > better way to deal with these issues especially while dealing
>>>> >> > with LateX rendering. Thanks!
>>>> >>>
>>>> >>
>>>> >> You don't show the code you're trying to use, so it's all a guess
>>>> >> as to
>>>> >> what's wrong. There are many possibilities.
>>>> >>
>>>> >> If you're going to display an image, you need to send it as an image.
>>>> >> My guess is that you're displaying it as text.
>>>> >>
>>>> >> Web pages are sent with a content-type of text/html. But if the web
>>>> >> page contains an image, the browser makes a second request to the
>>>> >> server
>>>> >> for the image. The image will be sent with a content-type of
>>>> >> image/jpeg, image/gif, etc. So the first thing you need to do is
>>>> >> ensure
>>>> >> you are sending the correct header when displaying it (in this case it
>>>> >> should be image/gif) (obviously this needs to be done in a separate
>>>> >> script from the rest of the page and accessed with an <img= tag).
>>>> >>
>>>> >> So what you could do is in your test page, put something like:
>>>> >>
>>>> >> <img src="testimg.php" ....>
>>>> >>
>>>> >> Then in your testimg.php file, fetch the file with file_get_contents
>>>> >> then display it with the correct headers, i.e.
>>>> >>
>>>> >> header ('Content-type: image/gif');
>>>> >>
>>>> >> Of course, if this is the only thing on your test page (it's sending
>>>> >> NOTHING else), you can skip the <img= ...> tag and just send the
>>>> >> correct
>>>> >> content-type at the start of your script.
>>>> >>
>>>> >> --
>>>> >> ==================
>>>> >> Remove the "x" from my email address
>>>> >> Jerry Stuckle
>>>> >> JDS Computer Training Corp.
>>>> >> jstucklex(at)attglobal(dot)net
>>>> >> ==================
>>>> >
>>>> > Pls have a look on the code:
>>>> > As you suggested my testing.php file code is as follows:
>>>> >
>>>> > <?
>>>> > $image = file_get_contents('users.gif');
>>>> >
>>>> > header('Content-Type: image/gif');
>>>> >
>>>> > //imagegif($image); // I also tried to display image with imagegif
>>>> > but it also didnt work.
>>>> >
>>>> > ?>
>>>> > The code of getimage.php file is as follows:
>>>> > <html>
>>>> > <img src="testing.php">
>>>> > </html>
>>>> >
>>>> > But the image is NOT displayed on the browser.Where I am wrong?
>>>> > Both php files and image (users.gif) is present in the same directory.
>>>> > I have also noticed that <img src= ""> do not work on the page where
>>>> > you have used header('Content-Type: image/gif'); ......... why?
>>>> >
>>>>
>>>> Where are you outputting the image? file_get_contents() does not output
>>>> anything.
>>>>
>>>> And no, <img src=..."> is an html command, and valid in pages with
>>>> content-type of text/html.
>>>>
>>>> I think your first problem is not understanding how html works. A
>>>> response has one content-type. A typical web page will have a
>>>> content-type of text/html, and will contain html code. <img src=....> is
>>>> an html command.
>>>>
>>>> Tags like <img src=...> (and many others) will cause an additional
>>>> request to be made to the server. If the content-type of the response
>>>> is image/gif, then the browser will only process it as an image. If it
>>>> is not a valid image, the browser will ignore it.
>>>>
>>>
>>> Ok. I got your point. But as it is the requirement of my project to store
>>> the complete question as an image in addition to storing latex text.
>>> Therefore I need to process the images (both question + options) and
>>> have to make them transform into a complete question.
>>> Therefore I thought that file_get_contents() may be helpful in this
>>> case as it then enable me to use imagecopy () and other functions.
>>> what you say?
>>>
>>
>> Why would a customer care whether the question is stored as a single
>> image or separate entries? In over 40 years of programming I've never
>> had such a requirement in a project. I admit I've had some stupid
>> requirements in the past - but I've always been able to convince the
>> customer why it should not be done that way. All part of being a
>> successful consultant.
>>
>> I would go back to the customer and explaining why it is a bad idea and
>> convince the customer to change the requirement.
>>
>
> To clarify: by stupid requirement I mean having to put the question and
> all the answers together into one image.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstucklex(at)attglobal(dot)net
> ==================

:)
Actually the application I am going to develop as a web app was developed by someone else as a desktop app. That application has several issues and most of the issues are on the side of data entry. Moreover due to some other reasons now there is a need to develop a web based app for Question entry. The test generation which is the other part of the app is very much stable.. The previous developer has kept the whole question as one image in the DB just for the sake of view while pick and choose of the question during the process of test generation. He was of the view that just for the sake of preview why should he pull the raw latex code and render it every time and then display. He thought it is better to keep the whole question as one image because it is just for preview purpose. Hope you got the logic now.

I know that there are other alternatives to solve this very scenario but as I said that test generation part of the app is stable and secondly I am short of time therefore I decided to restrict myself with the old design so that nothing else be disturbed. And yes the latex text is stored in separate fields and eventually used for the generation of test.
Re: Reading & Displaying Latex Rendered images [message #178573 is a reply to message #178572] Mon, 02 July 2012 20:54 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/2/2012 1:00 PM, Fastian wrote:
> On Monday, July 2, 2012 6:41:03 PM UTC+5, Jerry Stuckle wrote:
>> On 7/2/2012 9:35 AM, Jerry Stuckle wrote:
>>> On 7/2/2012 7:24 AM, Fastian wrote:
>>>> On Monday, July 2, 2012 3:53:13 PM UTC+5, Jerry Stuckle wrote:
>>>> > On 7/2/2012 2:42 AM, Fastian wrote:
>>>> >> On Friday, June 29, 2012 6:20:45 PM UTC+5, Jerry Stuckle wrote:
>>>> >>> On 6/29/2012 6:24 AM, Fastian wrote:
>>>> >>>> I am developing an application for the university. One basic
>>>> >>> > module/ section of this application is Data Entry. The data
>>>> >>> > is entered using Latex (Latex is a type setting language
>>>> >>> > and is not a WYSIWYG language). The tex software converts the
>>>> >>> > latex code into the required image. For better understanding
>>>> >>> > visit the following link:
>>>> >>>> http://www.forkosh.com/mathtexpreview.html
>>>> >>>>
>>>> >>>> You can see that on entering Latex code, the desired output
>>>> >>> > is obtained which is actually an image. This image is produced
>>>> >>> > by the Tex software and is being fetched and displayed on this
>>>> >>> > page. Another way to get that image is as follows:
>>>> >>>> <img src="http://www.forkosh.com/mathtex.cgi?$c=a+b$" alt=""
>>>> >>>> border=0 align=middle>
>>>> >>>>
>>>> >>>> My issue is that I want to get the image generated due to the
>>>> >>> > rendering of the Latex code and then display it after re-sizing
>>>> >>> > and then want store it in the MYSQL database.
>>>> >>>>
>>>> >>>> As I dont know the name of the image produced due to rendering
>>>> >>> > that's why I can not pick the image with its name. Therefore I
>>>> >>> > tried using function "file_get_contents". Though it returns
>>>> >>>> some garbage values on echo but what next?
>>>> >>>>
>>>> >>>> I need to know that how can I proceed further or suggest some
>>>> >>> > better way to deal with these issues especially while dealing
>>>> >>> > with LateX rendering. Thanks!
>>>> >>>>
>>>> >>>
>>>> >>> You don't show the code you're trying to use, so it's all a guess
>>>> >>> as to
>>>> >>> what's wrong. There are many possibilities.
>>>> >>>
>>>> >>> If you're going to display an image, you need to send it as an image.
>>>> >>> My guess is that you're displaying it as text.
>>>> >>>
>>>> >>> Web pages are sent with a content-type of text/html. But if the web
>>>> >>> page contains an image, the browser makes a second request to the
>>>> >>> server
>>>> >>> for the image. The image will be sent with a content-type of
>>>> >>> image/jpeg, image/gif, etc. So the first thing you need to do is
>>>> >>> ensure
>>>> >>> you are sending the correct header when displaying it (in this case it
>>>> >>> should be image/gif) (obviously this needs to be done in a separate
>>>> >>> script from the rest of the page and accessed with an <img= tag).
>>>> >>>
>>>> >>> So what you could do is in your test page, put something like:
>>>> >>>
>>>> >>> <img src="testimg.php" ....>
>>>> >>>
>>>> >>> Then in your testimg.php file, fetch the file with file_get_contents
>>>> >>> then display it with the correct headers, i.e.
>>>> >>>
>>>> >>> header ('Content-type: image/gif');
>>>> >>>
>>>> >>> Of course, if this is the only thing on your test page (it's sending
>>>> >>> NOTHING else), you can skip the <img= ...> tag and just send the
>>>> >>> correct
>>>> >>> content-type at the start of your script.
>>>> >>>
>>>> >>> --
>>>> >>> ==================
>>>> >>> Remove the "x" from my email address
>>>> >>> Jerry Stuckle
>>>> >>> JDS Computer Training Corp.
>>>> >>> jstucklex(at)attglobal(dot)net
>>>> >>> ==================
>>>> >>
>>>> >> Pls have a look on the code:
>>>> >> As you suggested my testing.php file code is as follows:
>>>> >>
>>>> >> <?
>>>> >> $image = file_get_contents('users.gif');
>>>> >>
>>>> >> header('Content-Type: image/gif');
>>>> >>
>>>> >> //imagegif($image); // I also tried to display image with imagegif
>>>> >> but it also didnt work.
>>>> >>
>>>> >> ?>
>>>> >> The code of getimage.php file is as follows:
>>>> >> <html>
>>>> >> <img src="testing.php">
>>>> >> </html>
>>>> >>
>>>> >> But the image is NOT displayed on the browser.Where I am wrong?
>>>> >> Both php files and image (users.gif) is present in the same directory.
>>>> >> I have also noticed that <img src= ""> do not work on the page where
>>>> >> you have used header('Content-Type: image/gif'); ......... why?
>>>> >>
>>>> >
>>>> > Where are you outputting the image? file_get_contents() does not output
>>>> > anything.
>>>> >
>>>> > And no, <img src=..."> is an html command, and valid in pages with
>>>> > content-type of text/html.
>>>> >
>>>> > I think your first problem is not understanding how html works. A
>>>> > response has one content-type. A typical web page will have a
>>>> > content-type of text/html, and will contain html code. <img src=...> is
>>>> > an html command.
>>>> >
>>>> > Tags like <img src=...> (and many others) will cause an additional
>>>> > request to be made to the server. If the content-type of the response
>>>> > is image/gif, then the browser will only process it as an image. If it
>>>> > is not a valid image, the browser will ignore it.
>>>> >
>>>>
>>>> Ok. I got your point. But as it is the requirement of my project to store
>>>> the complete question as an image in addition to storing latex text.
>>>> Therefore I need to process the images (both question + options) and
>>>> have to make them transform into a complete question.
>>>> Therefore I thought that file_get_contents() may be helpful in this
>>>> case as it then enable me to use imagecopy () and other functions.
>>>> what you say?
>>>>
>>>
>>> Why would a customer care whether the question is stored as a single
>>> image or separate entries? In over 40 years of programming I've never
>>> had such a requirement in a project. I admit I've had some stupid
>>> requirements in the past - but I've always been able to convince the
>>> customer why it should not be done that way. All part of being a
>>> successful consultant.
>>>
>>> I would go back to the customer and explaining why it is a bad idea and
>>> convince the customer to change the requirement.
>>>
>>
>> To clarify: by stupid requirement I mean having to put the question and
>> all the answers together into one image.
>>
>
> :)
> Actually the application I am going to develop as a web app was developed
> by someone else as a desktop app. That application has several issues
> and most of the issues are on the side of data entry. Moreover due to
> some other reasons now there is a need to develop a web based app
> for Question entry. The test generation which is the other part of
> the app is very much stable. The previous developer has kept the whole
> question as one image in the DB just for the sake of view while pick
> and choose of the question during the process of test generation. He
> was of the view that just for the sake of preview why should he pull
> the raw latex code and render it every time and then display. He
> thought it is better to keep the whole question as one image because
> it is just for preview purpose. Hope you got the logic now.
>
> I know that there are other alternatives to solve this very scenario
> but as I said that test generation part of the app is stable and
> secondly I am short of time therefore I decided to restrict myself
> with the old design so that nothing else be disturbed. And yes
> the latex text is stored in separate fields and eventually used
> for the generation of test.
>

Yes, developers are not necessarily smart. However, it sounds like you
aren't going to be able to use much of the previous code anyway, and
doing it right shouldn't take longer than trying to muscle what you have
into a bad design. It will also be more flexible and maintainable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Dreamweaver > can this be done?
Next Topic: Simulating a Form Method=Post submission in PHP
Goto Forum:
  

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

Current Time: Mon Nov 25 21:15:14 GMT 2024

Total time taken to generate the page: 0.04885 seconds