0

I am generating barcode images (using PHP-Barcode 0.4 http://www.ashberg.de/php-barcode/) with imagepgn but would rather not save them to disc - just seems unnecessary as the images aren't needed for long and they are small and quick to generate when needed.

I was thinking of an action showbarcodeAction that would just call the imagepgn function but there needs to be a template associated with the action right? And if so won't it produce some html when all I really need is the image? can I show the image in a standard img tag even though it is not actually saved to disc?

I am using typo3 v4.5 with extbase.

Thanks!

(Q also posted at http://forum.typo3.org/index.php/m/698624/#msg_698624 because when I tried to post it here first some error prevented this site from accepting it)

The Newbie Qs
  • 483
  • 8
  • 22
  • not sure if it is worth it but it is an idea I want to at least explore for curiosity's sake to see if it can work. – The Newbie Qs Nov 12 '13 at 16:22
  • It's generally preferable to save them to disk even when they are shown only a couple times because generating them can be relatively heavy on the server CPU-wise. Is this really worth the effort? What's the problem with the current process? Maybe rather build a script that frequently deletes old files – Pekka Nov 12 '13 at 16:22
  • Sorry, I deleted the comment accidentally and added it again – Pekka Nov 12 '13 at 16:23
  • Maybe rather build a script that frequently deletes old files – Pekka Nov 12 '13 at 16:23
  • You could base64 encode the image and pass it into the template; just as you would with any other property. For instance: http://jsfiddle.net/gq99X/ – Anthony Sterling Nov 12 '13 at 16:28
  • Another idea would be to generate the image in an eID-Script and just link to that eID-script in an img-tag. Maybe looking into the extension "dd_googlesitemap" would give some hints how to actually do that. – Jost Nov 12 '13 at 17:41
  • Anthony, that sounds like what I need, make that an answer rather than just a comment so I can accept it after I try it out. Just gotta get the image into base64, base64_encode() takes a string ... my $im image comes not from a disc read but is created with on the fly and last processed with the imagettftext() function. All examples I found so far read the file up from the disc. – The Newbie Qs Nov 12 '13 at 18:38
  • ... and when I pass in that $im to base64_encode I get null returned. – The Newbie Qs Nov 12 '13 at 18:46

1 Answers1

0

If you want to do it "your style", then generate your image in an action, modify the headers to return the right MIME type and add an exit at the end of your action. The exit will prevent Extbase from calling the view and therefore you won't need a Template.

This post could inspire you: http://buzz.typo3.org/people/soeren-malling/article/create-a-download-action-with-extbase/ You just need to remove the "push file" parts (content-description).

Personally I would go for the base64 way: Generate the image, encode it with base64 (PHP: base64_encode) and pass it to your Fluid template.

lorenz
  • 4,538
  • 1
  • 27
  • 45
  • tried it with exit but it just redirected back to the extensions main page and I never seen the image - I used die but I think its the same thing. I tried the base64_encode way but when I pass the image to the function it returns null so I'm not sure how to make that work; my image is the kind passed to the imagettftext() function, not just something read up from the disc with fread or file_get_contents. I guess I need to do something like this trick which looks a little hacky to me: http://stackoverflow.com/questions/8502610/how-to-create-a-base64encoded-string-from-image-resource – The Newbie Qs Nov 13 '13 at 14:54
  • If die() doesn't work in a controller action, either the controller isn't called at all or you have an early return/redirect/forward in this controller. As for the code in your linked sample, you may use it, just make sure to only pass the base64 encoded string to the Fluid template, don't echo the image tag :-). – lorenz Nov 14 '13 at 07:30