How to parse jpg as php and return jpg

I have a dynamic image that I am trying to create that previously worked on the same website until I found out that they removed some functions, some of which broke my image. I recently switched to hostgator, and I cannot get the image to work on my site. In fact, the PHP script is not important, since I'm completely sure that it works, because when I go to /image.php, it displays the image, but when I go to /image.jpg, it is not.

What I'm trying to do here is the PHP code inside the file with the JPG extension, which I have on /image.jpg, and not actually, but the PHP code. I need a server to parse JPG as PHP code, but return JPG so that I can use the image in places where only images with image extensions are allowed, such as forums. The forum I'm on will not accept an image with the PHP extension, so I need this to work as described.

The only thing I found and tried was to put this .htaccess:

<Files image.jpg> ForceType application/x-httpd-php </Files> 

The .htaccess file is in the same directory as the image, and this method also worked, but no longer works. I tested the image as PHP with hostgator and it works fine, I just need a way to use /image.jpg again.

In case this helps, what my PHP script does is take a background image, use ImageTTFText to change it to things like number of views, display of IP address and a few other things. As I said, the script itself works, I already tested it on the host server, but I need to be able to put the script in a JPG file and have it so that when someone views the JPG, it displays the image as intended.

Any help is much appreciated, thanks.

EDIT: The Rewrite trick in .htaccess didn't work either. It redirects image.jpg to image.php, and the forum still won't let me use the image. Also, with regard to the Apache configuration files, I am sure that I have access to this. I am not very good at it, but in cPanel I have access to Apache Handlers, which says that it allows me to control how the web server handles certain types of files. I just don’t know what I need here for it to work the way I need, but I think it might be what I need. If anyone knows if this will help, or how to use it, give some advice. Thanks.

EDIT: I don't know, this is what you mean, but here are the parts of creating the script image:

 Header ('Content-type: image/jpeg'); Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT'); Header('Pragma: no-cache'); $image = imagecreatefromjpeg("background.jpg"); $img_width = 514; $img_height = 128; imagepng($image); imagedestroy($image); 
+4
source share
1 answer

You can try something like

 RewriteEngine on RewriteRule image.jpg image.php [R=301] 

edited to add:

If you did not know this, you put this in your .htaccess file. Of course, the correct path is / in / file.

+2
source

All Articles