7 Replies - 1824 Views - Last Post: 12 May 2013 - 05:09 PM

#1 muirix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-June 09

Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 01:12 PM

Hello,
I'm creating an online language learning site that provides language drills. One of the drills is simply a multiple choice question asking the meaning of the word, the user chooses the option (form submission) and through php checks right or wrong.

My problem is that there are software's out there that provide translation of the word when you hover over it (see Rikaichan). I could solve this if the text were an image. But because the database is huge I can't possibly manually convert each text into a screenshot image, cropp and re-store it.

Anyone experienced know of any possible solutions?

Thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to output stored text as images? (images of the text)

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 01:45 PM

I do not have experience there, but most of the image libraries (e.g. GD) found in programming languages are capable of converting text into an image.
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,488
  • Joined: 12-December 12

Re: Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 01:46 PM

The PHP-GD library can convert text to images. There is a link on the left of the linked page to the ImageMagick library as well. I don't know the difference between these but I would guess that IM is more extensive.

I suppose you could use a procedure like this:

<?php
// Set the content-type
header('Content-type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?> 

from SO to create the image dynamically as the text is retrieved from the database, rather than having to create all the images and store them.

Of course, we cannot prevent anyone from cheating :bigsmile:
Was This Post Helpful? 1
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 01:47 PM

Hey.

There are ways you can have PHP generate an image based on text. See imagettftext, for example.

However, I have to ask. Why bother doing this in the first place? If the people using your site want to cheat, why waste time trying to stop them? It's not like they are hurting anybody but themselves, right?
Was This Post Helpful? 1
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 01:50 PM

View Postandrewsw, on 12 May 2013 - 10:46 PM, said:

Of course, we cannot prevent anyone from cheating :bigsmile:

as well as there is software to convert text to images, there is also software to convert images to text (namely OCR-software)
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 01:50 PM

View Postandrewsw, on 12 May 2013 - 08:46 PM, said:


The SO answer is a copy-paste from the manual entry :)
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3806
  • View blog
  • Posts: 13,488
  • Joined: 12-December 12

Re: Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 01:54 PM

View PostAtli, on 12 May 2013 - 08:50 PM, said:

View Postandrewsw, on 12 May 2013 - 08:46 PM, said:


The SO answer is a copy-paste from the manual entry :)

He, he. Yes, but when someone clicks my link to SO it then acknowledges the PHP help manual :)
Was This Post Helpful? 0
  • +
  • -

#8 muirix  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 05-June 09

Re: Is it possible to output stored text as images? (images of the text)

Posted 12 May 2013 - 05:09 PM

Fantastic! Thanks for the answers I will check out the php GD library and see what I can make of things!

With regards to cheating, yeah of course I won't prevent everyone from cheating haha. But it makes it more of a pain to cheat when you can't even copy and paste the word. It would probably be more effort cheating than it's worth, they'd might as well just guess the wrong answer.

Thanks again for the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1