PHP Script as Image

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hi,

I need a way to include a PHP script as an image.
Does anybody know how I would go about doing so?
Would I write my script then output image/png headers?

Thanks,
Undefined.
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
Are you talking about GD?

PHP:
<?php
header("Content-type: image/png");
$string = $_GET['text'];
$icfp = imagecreatefrompng("image.png");
$color = imagecolorallocate($icfp, 225, 225, 0);
$imgsx = (imagesx($icfp) - 7.5 * strlen($string)) / 2;
imagestring($icfp, 3, $imgsx, 9, $string, $color);
imagepng($icfp);
imagedestroy($icfp);
?>
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
No.
For instance, I want to be able to create a CRON Job.
But, I want to be able to do <img src="something.php" /> which leads to an actual PHP script but gives correct header with output buffering.
 

Doge

Active Member
Jan 12, 2012
174
40
Ugh I've done this ages ago where I had <img src="random.php" /> and it would load a random image from the script on random.php, It is possible for sure but I don't have the code :'c Just look around man :)
 

GarettM

Posting Freak
Aug 5, 2010
833
136
Are u sure u know what your asking?

But to answer your question:
HTML:
<img src="image.php" />
PHP:
<?php

Header('Content-Type: Image/png');

$image = file_get_contents('image.PNG');

Echo $image;

Also to get a certain image
PHP:
<?php
If(isset($_GET['SRC'])):
    If(file_exists("images/{$_GET[SRC]}.png")):
         $img = file_get_contents("images/{$_GET[SRC]}.PNG");
     Else:
         // get pack up or not found image
     Endif;
Endif;
?>

Sorry I am on my phone lollz
 
Last edited:

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
I don't think you guys understand.
I want to be able to include a PHP script as an image. I.e. <img src="path_to_script.php" /> and have it run a script in the background each time the page is loaded.
It needs to be an image. No iframes. I know it's possible because I've seen it done.
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
I don't think you guys understand.
I want to be able to include a PHP script as an image. I.e. <img src="path_to_script.php" /> and have it run a script in the background each time the page is loaded.
It needs to be an image. No iframes. I know it's possible because I've seen it done.
Sounds like you're trying to hack something (maybe using a shell?). What scenario are you trying to do this for?
the page has to be a php page, so if it's an html (.html) page and you're including it a php file it wont work
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Sounds like you're trying to hack something (maybe using a shell?). What scenario are you trying to do this for?
the page has to be a php page, so if it's an html (.html) page and you're including it a php file it wont work

I'm not.
I need a script to run in an HTML page (cannot include PHP).
I need to include an image so I can run CRON jobs everytime the page is loaded.
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
I'm not.
I need a script to run in an HTML page (cannot include PHP).
I need to include an image so I can run CRON jobs everytime the page is loaded.
as far as my knowledge goes you can't run a php file in an html page unless you use htaccess to make .html pretend to be .php
you could rename it to .php and have html in the .php file and then include the script like so:
Code:
<?php
//this is a php file
include('variables.php');
?>
<html>
 <head>
  <title><?php echo $title; ?></title><!-- just included a variable on a html page woa -->
 </head>
</html>
past that I don't think whatever you're trying to do isn't possible the way you're describing it to us
 

RastaLulz

fight teh power
Staff member
May 3, 2010
3,926
3,923
Do you not understand what a cronjob is? The OS runs them on a schedule..

If you want something to be executed via PHP every time a page is loaded and can't do it on the page(?), why don't you make a JavaScript call?

I really don't understand what you're on about? If you want PHP to be executed through an image call, you can do that with any page, it doesn't have to be an actual image. Teso even showed how to make an image using PHP..
 

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Taken from another open source system.
835875206f6d46e5cf200728645ebd9c.png

Which is including this file...
39a6cc17d2a89d227fc87e79b823a0ae.png


But my attempts to do something like this (even by copying this file and removing non-existant object calls) seems to fail.
 

Dicks

Member
Feb 9, 2014
58
19
Your whole question seemed sort of silly; I don't know why you would need to be able to call a PHP script by including it as an image on a .HTML page. If you told us why then we could probably give you alternatives to what you're doing.
 

Ryno

New Member
Jul 7, 2010
3
1
Taken from another open source system.
835875206f6d46e5cf200728645ebd9c.png

Which is including this file...
39a6cc17d2a89d227fc87e79b823a0ae.png


But my attempts to do something like this (even by copying this file and removing non-existant object calls) seems to fail.

This isn't a cron job at all (Cue RastaLulz's reply)
Do you not understand what a cronjob is? The OS runs them on a schedule..

The bit of script you have provided looks to be just making an image without the requirement of an external source (i.e. a .gif file sat in a separate folder)
The rest of it is just flushing the buffer?

I'm guessing you didn't provide the entire script but I think you really just need to explain exactly what you are trying to do, do you want to display an image that was generated by PHP or do you want to run 'background' tasks through this php file that is called from an image tag?
 

Users who are viewing this thread

Top