Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Single image src generation #9

Closed
zomars opened this issue Dec 23, 2016 · 14 comments
Closed

Single image src generation #9

zomars opened this issue Dec 23, 2016 · 14 comments

Comments

@zomars
Copy link

zomars commented Dec 23, 2016

I want to incorporate this extension to a current website I have but I'm using some pictures elements and some inline background-images with css.

It would be nice if I could generate a single image url without an img tag for me to use in other scenarios.

Thank you for making this extension and keep up the good work! 👍

@cdowdy
Copy link
Owner

cdowdy commented Dec 26, 2016

hmmm... yeah I could probably add this 1

Just spit-balling here.. I'll probably make a new twig tag since this could help with my problem I'm running into with generating a picture element (see #4). At least one aspect of it - having different crop directions for picture element sources not a full picture element -

  • [ 1 ] I'm not a fan of inline bg images using bitmap images but this isn't me using it so it doesn't matter haha

cdowdy added a commit that referenced this issue Dec 26, 2016
cdowdy added a commit that referenced this issue Dec 26, 2016
cdowdy added a commit that referenced this issue Dec 26, 2016
cdowdy added a commit that referenced this issue Dec 26, 2016
cdowdy added a commit that referenced this issue Dec 26, 2016
cdowdy added a commit that referenced this issue Dec 26, 2016
@cdowdy
Copy link
Owner

cdowdy commented Dec 26, 2016

Alright @zomars I've thrown something together https://github.com/cdowdy/boltbetterthumbs/releases/tag/v1.3.1

have a play around with it let me know any issues you come across please!

You'll need to use a different tag and config setup.

# Config setup:  
configName:  
  # all your modifications here
  w: 300
  h: 150
  fit: 'crop-top-left'

Template usage:

{{ bthumb( record.image, 'configName' ) }}  

@cdowdy cdowdy closed this as completed Dec 26, 2016
@zomars
Copy link
Author

zomars commented Dec 28, 2016

Will do! Thanks for the update!

@kutulus
Copy link

kutulus commented Feb 23, 2017

Hi,
I´m trying using the Template-Tag like mentioned:
{{ bthumb( record.image, 'configName' ) }}

My output looks like this:
the & is encoded as &
/img/2017-02/startseite-1.jpg?w=200&s=f9d2cc74b5ed7e8a6ee9d02d9c16249c

So the Url breakes :-(
Is there a trick or did I miss any necessary config?

MacOS: 10.12.3
PHP: 7.0.4
Bolt: 3.2.7
BetterThumbs: 1.5.7

regards,
Stefano

@cdowdy
Copy link
Owner

cdowdy commented Feb 23, 2017

hmm @kutulus you seem to be doing everything right. If you open the image in a new tab does the image work or does it say "operation not permitted"?

I changed somethings around earlier and I might have over looked the single image src generation so give me a bit and I'll test it out on my dev setup!

Sorry about breaking things if I did haha ;)

@cdowdy cdowdy reopened this Feb 23, 2017
@kutulus
Copy link

kutulus commented Feb 23, 2017

Hey cdowdy,
thanks for your quick response!
I get an "Operation Not Allowed"
If I replace the & with & then the Image works.

@cdowdy
Copy link
Owner

cdowdy commented Feb 23, 2017

ok.. that means there is a signature mismatch.

Did you pre generate these images through the back end prime page?

If you have a chance could you visit the back end files page (/bolt/extend/betterthumbs/files) and delete the image then try to use the image again in your template (unless you already have then don't haha).

I thought I stomped out all these url encoding quirks earlier but chances are I didn't haha

@cdowdy
Copy link
Owner

cdowdy commented Feb 23, 2017

hmm I just tried on Apache and Nginx..

here is my betterthumbs.cdowdy.yml config:

single:
  w: 200  

Here is my index.twig template:

 <img src="{{ bthumb( record.image, 'single' ) }}" alt="placeholder alt text">  

Are you using this in a background image by chance?

@kutulus
Copy link

kutulus commented Feb 23, 2017

Yes, I´m trying to set a background-image like this:

`<style media="screen">

section.hero { background-image: url('{{ bthumb(record.image, 'single') }}'); }

</style>`

@kutulus
Copy link

kutulus commented Feb 23, 2017

Did you pre generate these images through the back end prime page?

If you have a chance could you visit the back end files page (/bolt/extend/betterthumbs/files) and >delete the image then try to use the image again in your template (unless you already have then >don't haha).

... tried with no result :-(

@cdowdy
Copy link
Owner

cdowdy commented Feb 23, 2017

@kutulus yeaaaah.... drats thats a problem haha.. the ampersands in the url inside a style tag cause problems.......

if you apply the image directly to the section tag you can use single quotes... ie:

<div style="background-image: url( '{{ bthumb( record.image, 'single' ) }}' ); width: 200; height: 200; ">
  <p>hi</p>
</div>

But that isn't a very good / maintainable solution... Give me a bit I'll see if I can "properly" fix it and allow usage inside a style tag....

My fault for not properly testing that out haha I apologize!

@kutulus
Copy link

kutulus commented Feb 23, 2017

ahhh, I see. – the workaround works, thanks for that.
But a properly solution would be a charm... :-)

@cdowdy
Copy link
Owner

cdowdy commented Feb 23, 2017

well.. I have a solution :) and I'll push a new release here in a few moments...

I wrote these really complicated filter methods and decoded url's and all this and.... well I didn't even need to haha. I just used the twig raw tag. you can apply this fix too if you don't wanna wait on a new release to hit bolt's extension service..

Go into my extension ( /extensions/vendor/cdowdy/betterthumbs and then go into templates and open up global.macros.html.twig and you'll see a macor block called "setImg"

add the |raw filter to srcImg as show below and save and you should be good (fingers crossed) haha.

{# test out for not found and single image right now #}
{%  macro setImg( srcImg, sourceExists, notFoundImg ) %}
{% if sourceExists %}/img{{ srcImg|raw }}{% else %}
{{ notFoundImg }}{% endif %}
{% endmacro setImg  %}  

@cdowdy cdowdy closed this as completed in 0d67073 Feb 23, 2017
cdowdy added a commit that referenced this issue Feb 23, 2017
fixes #9 adds a raw filter so images can be used in in page style tags
@kutulus
Copy link

kutulus commented Feb 23, 2017

... seems to work fine!

Tanks for your quick solution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants