Please tell me how to convert text to image

Discussion in 'PHP' started by salahsoftware, Oct 23, 2008.

  1. #1
    I need to convert HTML into image so that no one should be able to copy it. The code should be in php without any javascript used for conversion.

    A simple code is appreciated however, if you know a class for it then also inform me.
     
    salahsoftware, Oct 23, 2008 IP
  2. sastro

    sastro Well-Known Member

    Messages:
    214
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #2
    sastro, Oct 23, 2008 IP
  3. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I need to convert a text with plain html into an image. Not the complete webpage. I need the php code.
     
    salahsoftware, Oct 23, 2008 IP
  4. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    what do you mean? render the HTML? just display the text on the site as image? in that case, look into gd
     
    Kyosys, Oct 23, 2008 IP
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    You mean a script that get snapshots of the page?
     
    Kaizoku, Oct 23, 2008 IP
  6. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I mean a formatted <div> with <b> <table> etc. in the html to be converted to image. Rest of the area will remain text for search engines to find. I just want to protect the main information from being copied.
     
    salahsoftware, Oct 23, 2008 IP
  7. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    My question is entirely different from this thread forums.digitalpoint.com/showthread.php?t=358968
     
    salahsoftware, Oct 23, 2008 IP
  8. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can't replace tables without images without also making the text an image. This is impossible, and you are being paranoid
     
    Kyosys, Oct 23, 2008 IP
  9. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You (almost) all got him wrong.. salahsoftware, as someone said, this can be done with GD. I'm just wondering is it worth it. Think about it.. if I wanna steal your content (not that I do that kind of stuff anyways..), converting the text to an image will delay me, but can never stop me! Think about is what you're trying to do worth the effort of doing it :)
     
    xlcho, Oct 23, 2008 IP
  10. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    hi xlcho,

    I am creating a skill testing site. I want to convert the test questions into image so that the user cannot copy and paste the question in google to find out the answer. If the user type the question in google, it will take time, therefore the total time for answering question will expire.

    Hence, the logic is to ensure that the user does not cheat the test system by copy-pasting the question to find out answer.

    Thanks in advance
     
    salahsoftware, Oct 23, 2008 IP
  11. salahsoftware

    salahsoftware Peon

    Messages:
    63
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I know how to convert plain text to an image. I have created captcha earlier, however the point is to convert the html code into image so that the text looks formatted.
     
    salahsoftware, Oct 23, 2008 IP
  12. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #12
    i think he is asking for making a html rendering engine in php with the gd
     
    octalsystems, Oct 23, 2008 IP
  13. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #13
    Yea, that can be done easily:

    
    <?php
    header ('Content-type: image/png');
    $im = @imagecreatetruecolor(120, 20)
          or die('Cannot Initialize new GD image stream');
    $text_color = imagecolorallocate($im, 233, 14, 91);
    imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    
    PHP:
    This will output an image with the words 'A Simple Text String' on it.

    This is kind of a bad way to do it though. . . Why not just use css and stretch an opaque image across the question? I've seen that done before and it will stop most people from copying and pasting. . .
     
    ToddMicheau, Oct 23, 2008 IP
  14. silencer01

    silencer01 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I think it is no need to do that,
    Although you can converted the page to image use code,
    The one can't copy on your web, but the page can be saved to pc,
    Open it on Dreanware or other editor, Then they can copy your HTML easily.
     
    silencer01, Oct 23, 2008 IP
  15. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #15
    Example based on GD is alredy provided. And advanced example for colors and custom ttf font may be consulted in the code of DPI 1.1, in upload.php, I created here.

    Example:

    <?
    	$text = "
    	<html>
    	<head>
    	   <title>some title</title>
    	</head>
    	<body>
    	   Here goes content
    	</body>
    	</html>";  
    
    	$padding = 10; #10px
    
    	$fsize = 12; #font size 12 pixels
    
    	$ttf  ="./Tahoma.ttf"; #path to windows ttf font file
    
    	$size = imagettfbbox($fsize, 0, $ttf, $text);
    
    	$xsize = abs($size[0]) + abs($size[2])+($padding*2);
    	$ysize = abs($size[5]) + abs($size[1])+($padding*2);
    
    	$image = imagecreate($xsize, $ysize);
    
    
    	$white = imagecolorallocate ($image, 255, 255, 255);
    	$black = imagecolorallocate ($image, 0, 0, 0);
    	imagefilledrectangle ($image, 0, 0, $xsize, $ysize, $white);
    
    	imagettftext($image, $fsize, 0, $padding, $fsize+$padding, $black, $ttf, $text);
    						
    			
    	#save to file
    	imagejpeg($image,"./screenshot.jpg",85); #85%quality
    ?>
    PHP:
    I hope it helps.

    regards
     
    Vooler, Oct 24, 2008 IP
  16. octalsystems

    octalsystems Well-Known Member

    Messages:
    352
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    135
    Digital Goods:
    1
    #16
    is there any html rendering engine available in gd
    in which we can just pass the html and it will render the output as displayed on browser?
     
    octalsystems, Dec 8, 2008 IP
  17. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #17
    the problem is that you need a browser to render it, then a program to create a virtual screen for that browser to work on, then a program to make a screencapture of that.

    gd != html rendering engine, gd == graphics engine.

    the first reply in this post seems a valid solution for what you want to do, but you'd have to install a windows server somewhere that can do it for you.
     
    rene7705, Dec 8, 2008 IP
  18. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0