0

I am in the process of writing Joomla functionality that will produce JPEG-images on the fly using Imagick and GD. It is supposed to be used in Joomla articles like this:

<IMG src="/index.php?option_com=mycomponent&id=524&width=800...." alt=" .... " />

I have managed to get the code to work in PHP with direct access to the database and the file system, but I want to integrate it into Joomla as an extension (not necessarily a component) to take advantage of Joomla's security, access management, logging and more.

However, it seems that Joomla extensions always return their output to Joomla which then merges the output with other elements before sending the whole thing off to the browser.

I want to avoid direct access from outside to temporary files, so instead my extension should generate the dynamic image and send it off to the browser with the correct headers. That means that the extension must circumvent Joomla and send to the browser directly. How would you accomplish that?

NB: Tried Base64 encoding directly into the image tag, but could not make it work.

1 Answer 1

1

It sounds like you're using default view behaviour, ie show an entire html page. In your component just jexit after you dump the image data. You don't need any modules or template and all your permission checking should already be done.

$img = new Imagick($file);
// do some image manipulation here
header('Content-Type: image/'.$img->getImageFormat());
echo $img;
jexit();

A post on dumping an image to the screen from imageMagick: https://stackoverflow.com/questions/4932100/output-raw-image-from-imagick-image-in-php

2
  • Thanks a lot @jamesgarrett. You are right about about using default view behaviour. I will test your solution and credit you as soon as I have validated it. Commented Dec 30, 2020 at 0:04
  • It worked like a charm, @jamesgarrett, so I credited you for giving the right answer to my needs. Thanks a lot. Commented Dec 30, 2020 at 14:04

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.