0

I've run into this issue where we have created a custom style (emailthumb) which is to be used when sending out email newsletters via simplenews. The thumbnail is based on 'thumbnail' style but is slightly bigger. It works fine when the image is being rendered as 'thumbnail' or any other style but not the one custom style.

The permissions of the folders are all exactly the same (I've even tried 777 for emailthumb->public) as in 'thumbnail' but there is no pictures folder being created. I then get a log error of access denied as the url to the image as the folder does not exist

http://example.com/sites/default/files/styles/emailthumb/public/pictures/image.jpg

I have tried changing the theme as per image style (imagecache) images are not being created but this has not worked.

Does anyone have any suggestions?

Current Permissions sites/default 555

  • anything in the watchdog (recent log messages) ? anything in the apache (or other webserver) log ? – rtome Mar 31 '15 at 8:46
  • might be on to something there. drush watchdog-show, and error log show the same 'access denied' with the url including the pictures folder that doesn't exits. Server error log shows Directory index forbidden by Options directive: /home/domain/public_html/sites/default/ – Inigo Montoya Mar 31 '15 at 8:57
  • looks like a permissions problem. – rtome Mar 31 '15 at 9:00
  • Ok I've added the current permission of the default folder. Is this where the problem lies? – Inigo Montoya Mar 31 '15 at 9:16
  • changing sites/default to 755 removes the server errors but nothing else has changed. Tried deleting and adding the style again and also swapping the theme over. No effect – Inigo Montoya Mar 31 '15 at 9:34
0

The problem was that the image style was never being called to save the image in the first place. The following code forces the image to save for this use case.

function MODULE_node_presave($node){
  // Get some field items from a field called 'field_image.
  if ($image_items = field_get_items('node', $node, 'field_image')) {
    $image_item = array_shift($image_items);

    // Load the associated file.
    $file = file_load($image_item['fid']);

    // An array of image styles to create.
    $image_styles = array('emailthumb');

    foreach ($image_styles as $style_name) {
      // Get the location of the new image.
      $derivative_uri = image_style_path($style_name, $file->uri);
      $style = image_style_load($style_name);
      // Create the image.
      image_style_create_derivative($style, $file->uri, $derivative_uri);
    }
  }
}

credit here force image style generation on save node

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.