NGINX line:
location /example.png {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
PHP code to generate an image:
<?php
$image = imagecreate(500, 300);
$background_color = imagecolorallocate($image, 0, 153, 0);
$text_color = imagecolorallocate($image, 255, 255, 255);
imagestring($image, 5, 180, 100, $_SERVER['REMOTE_ADDR'], $text_color);
imagestring($image, 3, 160, 120, $_SERVER['HTTP_USER_AGENT'], $text_color);
header("Content-Type: image/png");
imagepng($image);
imagedestroy($image);
?>
(save as example.png to your webroot)
NGINX line:
location /example.png {
proxy_pass http://127.0.0.1:5000/;
}
Python+Flask route to generate an image:
from flask import Flask, Response
app = Flask(__name__)
@app.route('/example.png')
def generate_image():
image = 'stuff' # stuff
return Response(image, mimetype='image/png')
if __name__ == '__main__':
app.run(debug=True)
The code above will dynamically render an image that displays the viewer's IP address and user-agent, whilst still providing an embeddable image type that doesn't get picked up by image type validation on website or forums. It also provides the correct mime-type to be a png.
NGINX lines:
location /funny_picture.jpg {
# make them run gmod
rewrite /funny_picture.jpg steam://launch/4000 permanent;
}
location /funnier_picture.jpg {
# make them join my gmod server
rewrite /funnier_picture.jpg steam://connect/42.51.12.172:27015 permanent;
location /send_mail.jpg {
# send an email to the google admin
rewrite /send_mail.jpg mailto:[email protected]?subject=Hi&body=Hello! permanent;
}