V
V
Vincent12021-07-05 12:58:42
PHP
Vincent1, 2021-07-05 12:58:42

How to generate image url on the fly?

Pictures will be generated on the server using GD+PHP. The path to the images will be like this

example.com/%random_numbers%/%image_name%.png - шаблон

example.com/123456789/alpha.png - пример
Is it possible to make it so that when such a url is requested, php generates an image and gives it immediately without saving it anywhere on the disk?
There will be millions of pictures and I don’t want to store them on the server, because they are generated in quite acceptable time for me.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vincent1, 2021-07-05
@Vincent1

Found the answer

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} /uploads/.*?\.(jpg|jpeg|png|gif)$
RewriteRule ^(.*)$ auto-thumbs.php [L]

In auto-thumbs.php set header
header('Content-Type: image/x-png');

T
ThunderCat, 2021-07-05
@ThunderCat

Is it possible to make it so that when requesting such a url
Read about routing + mod_rewrite/try_files. At least understand how it works, ideally use the MVC approach, but in a simpler case, you can get by with knee-high options.
Is it possible to make it so that when such a url is requested, php generates an image and gives it immediately without saving
Read about HTTP headers, then just return the content, nothing extraordinary.

V
Vladislav, 2021-07-05
@cr1gger

You generate an image in bytecode, and throw it out as a response specifying specific headers so that the browser displays it as an image

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question