This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

dweimer
dweimer

I have some code on my current website that generates dynamic images Like This One, which overlays data from an Acurite weather station gathered by WeeWX over top of a web cam still image capture. I have taken to use .php.jpg, .php.gif, .php.png as extensions for these files that way the web server can be told to process them through PHP and the clients browser knows they are image files.

I am trying to figure out how, if its possible to handle this type of content within the CMS, just to manage everything from a single point. It seems that I can't really save files using any thing but a few limited extensions. In this case is this something that's best kept out of the CMS system?

jan-vince
jan-vince

What role should October has in this?

Do you want to process this files inside October?
Maybe create special page with onStart() function to process images and use scheduler to trigger processing?

Or just save final images to show on some page?
It should be enough to save images into /storage/app/media directory to appear in media pane in backend and create onStart() function that get files list and send array to Twig

dweimer
dweimer

I guess it could be possible to use an onStart function to trigger the file be saved, that just seems like extra overhead to me rather than returning the image straight from memory. Here is a sample set of code, This would simply return an image pulled from an internal http resource and display it as if it was served as a static file from the web server itself instead.

<?php
 $HTTP_ENV = new http\env();
 $HTTP_ENV->setResponseHeader( "Cache-Control", $header_value="must-revalidate, max-age=0", $response_code=0, $replace=True );
 $HTTP_ENV->setResponseHeader( "Content-Disposition", $header_value='inline; filename="snapshot.jpg"', $response_code=0, $replace=True );
 $HTTP_ENV->setResponseHeader( "Content-Type", $header_value="image/jpeg", $response_code=0, $replace=True );

 $SnapShot = imagecreatefromjpeg( "http://10.9.5.134/snapshot.jpg" );
 imagejpeg( $SnapShot );
 imagedestroy( $SnapShot );
?>

I am doing more in the real file, the backend camera requires a a json formatted login process that is using php curl extension to handle submitting the authentication and returning the image data. Then the image is resized and a text block is written on top of the resized image.

In the end the file is simply a plain text php file with a different extension, by adding .php.jpg the server knows to process it as a php file, but the client browser sees it as an image file. This isn't stictly necessary most browsers handle a php file returning image data properly, but doing this simple trick makes the web page conform to best practice standards and images have a proper image extension.

Yes it can easily be done by including a directory structure that is managed outside of the CMS for this content. I just thought it would be handy to be able to edit the files within the same interface as the rest of the content.

jan-vince
jan-vince

How about create a plugin for this with two parts:

  • one to create images and save to /storage/app/media dir and maybe save image record info to DB - this part doesn't have to be connected to any page - just be triggered by scheduler or regular cron job
  • second to be used by pages to list images (or other usage)

I guess that would be probably the cleanest solution...

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.