1

I have need to be apply an Image Style setting to the logo uploaded at appearance/settings/THEME_NAME

Use Case is: The theme will be used across multiple unique instances within the organization and associated groups, each with different branding. The installation will be via an Install Profile including preset Image Styles. The logo will need to be set by the individual installing the site. It is a requirement that this individual will not need the skill to modify a tpl file in order to set the logo path/size or use any image editing software to modify the logo's dimensions pre upload.

... where to begin?

I suspect there are two routes:

  1. Modify the existing logo field via page.tpl.php to use a predefined image style.
  2. OR Add a new Image field to the Theme's settings form and calling that in page.tpl.php

Either task is pushing my Drupal ability so before I begin I thought I would ask for opinions on my assumed solutions above or better yet, actual solutions to setting image styles for the logo upload. :)

Thanks in advance, Nick

3

You should be able to alter the logo-path in hook_preprocess_page and replace the logo path with the path of the transformed logo:

function mytheme_preprocess_page(&$variables) {
  $variables['logo'] = image_style_url('my_image_style', $variables['logo']);
}

Didn't try it out, but it should work somehow this way.

edit: there is a LOT of "logo" in my first sentence ;)

  • of course, I frequently under estimate the power of the preprocess! Thanks I'll try it out and report back. Cheers, Nick. – Nicholas Aug 2 '11 at 17:38
  • This gives me a bad path http ://styles/style_name/http/... – Charles Bandes Apr 24 '13 at 18:47
0

This is a design flaw in Drupal. Unfortunately, $logo is a bare HTTP URL, but there is no standard function available to convert a HTTP URL to the Drupal URI that the image_style_url function needs. However, you can convert the URL manually like this:

function mytheme_preprocess_page(&$vars) {
 $vars['logo']=image_style_url('my_image_style',str_replace($base_url.'/sites/default/files/','public://',$vars['logo'])); 
}

Please have a look at this and be aware that the solution above involves hard-coding (and is not very pretty).

0

I created a module Logo Image Style which lets you choose an image style for your site logo.

Logo Image Style:

Logo image style allows the site builder to use image styles to render the theme logo. The used image style can be set on a per theme basis.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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