Search code examples
phphtmlonmouseover

How to make an image hover over another and export it as an image


Ok, so i have a question. First let me post this:

<a href="#"><img src="http://i.imgur.com/ZRjnZlR.png" onmouseover="this.src='http://i.imgur.com/GPI0JA5.png'" onmouseout="this.src='http://i.imgur.com/ZRjnZlR.png'" /></a>

That's an html code that hovers an image. This works perfectly, the only problem is that i don't need it as an html code but i want to make it into a php file, since i'm on a forum that doesn't allow html.

So, how would i make that html code into a php, turn the outcome outcome into a png files so it looks like this and the outcome isn't this.

Remember, i'll be using bbcode to display that hover as an image.

By export image, I mean header("Content-Type: image/png");


Solution

  • Just create a ".php" file and echo the html code within php code:

    <?php
        $img_src = 'http://i.imgur.com/ZRjnZlR.png';
        $mouseover_src = 'http://i.imgur.com/GPI0JA5.png';
        echo('<a href="#"><img src="' . $img_src .
            '" onmouseover="this.src=\'' . $mouseover_src . 
            '\'" onmouseout="this.src=\'' . $img_src . '\'" /></a>');
    
    ?>
    

    Edit:

    You can set a header with the PHP "header()" function, like so:

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