I'm working on a module. It uses an API to serve images. One of it's features is calling for a custom resolution image by GET request. So for example
myapi.com/img4324342?w=22&h=55.
I'm currently abusing the style function from the Image module.
I call hook_preprocess_image() and if it detects my effect (my custom style that has my custom effect) it has to return a modified path. But the path get's malformed when I apply a style. I just want to have the original URI so I can use the information inside to construct a REST call. How to prevent that the URI changes after style a.k.a. how to return the original URI as Path?
Background:
It's a brand portal and I'm an intern making the drupal plugin. The company I work for doesn't want the images to be served from the Drupal hosting, only provided by the API. But they ALSO want that adding a different banner for example to every article is still done the same way you normally do: by adding a image style and adding it as a field to the content type
The $vars variabele from hook_preprocess_image()
in json looks like this:
{
"path":"?itok=D1zdawxe",
"alt":null,
"style_name":"thumbnail",
"width":null,
"height":null,
"title":null,
"attributes":[],
"theme_hook_original":"image",
"theme_hook_suggestions":[]
}
after applying any effect.
This means that when I don't apply any effect my Path (my Uri) is myscheme://img23423423432
and when I do apply ANY effect it get's malformed to random gibberish like ?itok=D1zdawxe
public://image.jpg
changes topublic://styles/foo/image.jpg
? If so, that's what's supposed to happen. To get around it, simply copy the image file you've just created to the path you want to serve it from. You would have to have the original URI to even get the new style URI, so it's not clear why you're asking how to get that - you already have it, surely? You should post the relevant code to resolve all these ambiguities, your current explanation isn't detailed enough to understand what you're doingmyscheme://image423423
to?itok=D1zdawxe
hook_preprocess_image_style
instead (that comes beforetheme_image()
in this case) - see what vars you have available in that hook