0

I have used the construct <img src="http://yoursite.com/image.php?request_id=XXXX"> and it works well to serve images that may need some preprocessing. However, if image.php requires a lot of arguments, the src can become very clumsy. Therefore I thought of wrapping image.php into a function, and bundling it to my content page with include_once "image.php".

The strategy, however, produces the dreaded "Cannot modify header information" error. I believe this is because there is already output on the page, before the img is referenced. Does that mean that it is impossible to output an image src by function rather than by GET a separate file?

1
  • 1
    It's not completely impossible, but it's inadvisable for many reasons. But you could store all the parameters in a session variable, for example. Commented Jul 29, 2012 at 10:19

1 Answer 1

1

This will not work because you are sending two different types of contents in one response, one is text/html and the other for example image/jpeg. Here is my suggestion: have a function that accepts all the arguments you need to render the image and have this function save it somewhere on the disk (cache/images for example) the function should then return the path to this image so you can put it in you src.

Sign up to request clarification or add additional context in comments.

1 Comment

I had such concept like you are having for quite a while, the problems are: you are always rendering image on request instead of serving an already rendered one. Because this is a CPU and MEM intensive operation you are also voulnrable to an attack which could completely drain your hardware resources.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.