SYMPTOM: Several reports indicate that after upgrading media the thumbnail images in the media browser are gone

workaround: the square_thumbnail image style is missing, so add it manually.

TODO:

figure out why this is sometimes happening for some upgrades, but not all upgrades and come up with a patch to fix this permanently.

CODE: have a look at the media.install , hook_update 7211 , it looks ok, but there may be a problem

In some upgrade scenarios, (need exact steps to reproduce, which has not yet been put forward) the 'square_thumbnail' is not created correctly.
Here is the code that is supposed to create the square_thumbnail (if it is missing):

/**
 * Save a square_thumbnail image style in the database for legacy support if one
 * does not already exist.
 */
function media_update_7211() {
  $default_style = array(
    'name' => 'square_thumbnail'
  );

  // Clear the image cache to remove any old image styles that only exist in
  // code.
  cache_clear_all('*', 'cache_image', TRUE);

  // Check if the square_thumbnail image style exists.
  // The style will only exist if the user has customized it, otherwise it would
  // have been removed by clearing the image style cache.
  $existing_style = image_style_load('square_thumbnail');

  // Save a square_thumbnail image style in the database for legacy support.
  // This is only necessary if a square_thumbnail image style doesn't already
  // exist.
  if (empty($existing_style)) {
    $style = image_style_save($default_style);

    $effect = array(
      'name' => 'image_scale_and_crop',
      'data' => array(
        'width' => 180,
        'height' => 180,
        'weight' => 0,
      ),
      'isid' => $style['isid'],
    );

    image_effect_save($effect);
  }

  return t('Saved a square_thumbnail image style in the database for legacy support if one did not already exist.');
}

ORIGINAL SUMMARY:

I have strange bug on one of my sites. The media browser doesn't find the images and display them as broken (or rather the browser shows broken images). The display of images in the theme works just like it should. So the files are identified and recognized. It is something in the "backend/editor role" display of the files that is broken. Is this a known problem with an easy fix? I'd love to get it sorted out.

I have an example file
a_test.jpg

when I upload it and publish it in an Article type test node (once in an image field and once inserted through wysiwyg in the body) it is stored in three loacations.

/sites/default/files/a_test.jpg
/sites/default/files/styles/large/public/a_test.jpg
/sites/default/files/styles/epsacrop_thumb/a_test.jpg (epsacrop_thumb is an image style of my making)

When I try to view it in the Media Browser library or on /admin/content/file/thumbnails the images are not found, they have the file path of
/sites/default/files/styles/square_thumbnail/public/a_test.jpg

So for some reason no image is created in the folder /square_thumbnail/public which seems to be what Media Module expects.
I read somewhere that the square_thumbnail has been replaced by media_thumbnail. But when I manipulate the file path in the image tag to be /sites/default/files/styles/media_thNot sure why you'd have to manually create square_thumbnail , umbnail/public/a_test.jpg I don't get any image either.

Another strange thing is that image field is configured use the file directory "field/image". But the image is save straight into /sites/default/files/. Shouldn't this be /sites/default/files/field/image ?

Any help would be greatly appreciated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

leanderl’s picture

Issue summary: View changes
leanderl’s picture

Status: Active » Closed (won't fix)

So I tried to have look at how it all is connected and realised that there is no image style called square_thumbnail in my Drupal installation. So I created such an image style which solved the problem.

Media.install states something about keeping the image style for legacy support. in the comment on row 904. Strange that it is missing and strange that my current version of media, which has set an image style called 'media_thumbnail' doesn't use 'media_thumbnial', but for some reason clings to the 'square_thumbnail' style which if I understand things right, is now depracated.

Anyway my current problem is solved and I'm happy as Larry. Just don't understand how it came to be.

Mark_L6n’s picture

@leanderl, thanks for posting the solution. After upgrading, my site also did not have a 'Square thumbnail' image style anymore. (The key thing is likely to have the machine name 'square_thumbnail'). Copied the settings from the new 'Media Thumbnail' image style, Scale and crop 100x100, to 'Square thumbnail' and thumbnails now exist again.

loparr’s picture

I upgraded just now - thumbnails do not show. However, module is calling media_thumbnail not square_thumbnail. Instead of thumbnails I am getting /files/styles/media_thumbnail/public/media-icons/default/image-x-generic.png

loparr’s picture

Status: Closed (won't fix) » Active

updating status, why is this wont fix?

m.roma’s picture

I have the same exact issue: it's driving me crazy, as I have tried everything a number of threads suggest: including this "Square thumbnail" solution in the image styles. The reference for the image is still to a non-existant directory (i.e. media_thumbnail).

Any other ideas?

loparr’s picture

Priority: Normal » Major

Changing issue to major. Using popup browser is useless without seeing picture thumbnails.

loparr’s picture

Has anyone found a solution for this yet?

Sagar Ramgade’s picture

Status: Active » Needs review
FileSize
544 bytes

It seems image_style_load might be giving values from the cache table, so the patch attached clears image styles from the cache table first before loading it.

Spanners’s picture

#2 worked for me. A little surprised I didn't have a square_thumbnail image style in there, but when I added it (ensuring machine name is square_thumbnail), Media Library was back to normal.

No patch required for me.

leolandotan’s picture

Im having the same issue with the latest version of Media(media-7.x-2.0-beta2) and Core 7.44. I noticed this when transferring the site from production into my local and tried to upload an image that uses the Media Browser.

After creating the square_thumbnail image style following its settings from media-7.x-1.5, everything worked normally.

Kukulcan’s picture

#2 did the trick for me too...thanks

undersound3’s picture

I experienced thumbnails not showing when upgrading from 7.x-2.0-alpha3 to 7.x-2.0-rc3.
Creating the image style square_thumbnail did not work for me but this solution did https://www.drupal.org/node/1388106#comment-8318231

itpathsolutions’s picture

function themename_image_widget($variables) {

  $element = $variables['element'];


   //echo"<pre>";print_r($element['#entity']->field_image['und'][0]['uri']);echo"</pre>";
     
      if($element['#entity_type']=="node")
      {
          $uri = $element['#file']->uri;
          $output = '';
          $output .= '<div class="image-widget form-managed-file clearfix">';
          $image_view_src= file_create_url($uri);
          if (isset($element['preview'])) {
            $element['preview']['#markup']="add image tag and this image tag add set path";
            $output .= '<div class="image-preview">';
              $output .= drupal_render($element['preview'] );
            $output .= '</div>';
          }

          $output .= '<div class="image-widget-data">';
          if ($element['fid']['#value'] != 0) {
            $element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
          }
          $output .= drupal_render_children($element);
          $output .= '</div>';
          $output .= '</div>';

          return $output;
  }
} 
joseph.olstad’s picture

Last commenter, please edit your comment wrap code in code tags or php tag for markup and formatting

OwilliwO’s picture

Hello there.

Just to say I was waiting for stable 2.0 release to migrate, and I'm very disappointed.
This problem is still available, I have to handle myself creation of square_thumbnail image style.

You really should find a way to avoid this problem.

joseph.olstad’s picture

Issue summary: View changes

@OwilliwO , almost 20,000 installations have already been upgraded to 7.x-2.0 . There's not a whole lot of noise in the media issue queue these days, not like there was when the 7.x-2.x branch was in beta.

I'd like things to work perfectly for everyone, there's improvements to be made. If you want to help out have a look at media.install media_update_7211() , this upgrade is creating square_thumbnail for you if you don't already have one. So perhaps the one you already had was problematic or there was some other issue. Not sure why you'd have to manually create square_thumbnail.

It seems that this works for most installations, but not all but it actually takes someone testing and re-testing the upgrade in several scenarios.

OwilliwO’s picture

Thanks for the answer.

When I have a look inside media.install, I found hook_update_7211, and understand that square_thumbnail should exist.
Actually, I'm not able to understand why it doesn't one my site.

As all is OK for me, let's forget about this problem.
I'll have a look if I have enough time.

joseph.olstad’s picture

I do admit that there is a problem with square_thumbnail not always being created, however I'm not sure to what extent the problem is, I know that it does not affect fresh installs, however for upgrades I'm not sure why some or how many square_thumbnail image styles don't get created and in which environment settings (versions upgraded from and to).

thoughtcat’s picture

Since updating to 7.x-2.0 whenever I try to upload images into a content type via an "image" file field, I get a 500 error, and the whole content is lost. The log messages were showing "page not found" for square_thumbnail and when I checked in /admin/config/media/image-styles there was no such style, only "Media thumbnail". I renamed that square_thumbnail, which actually had the effect of creating a new style by that name and keeping media thumbnail. This has made no difference to my problem (I have cleared all caches). I can create content but only if it doesn't require me to upload any images into it, which is useless. I also have a (presumably related) issue where uploading images into body text using the "add media" icon gives a blank "media browser" window - reported separately in the issue queue (https://www.drupal.org/node/2878006). My site was running fine on 7.x-1.4. All other related modules are up to date.

joseph.olstad’s picture

@thoughtcat , your environment debug information has some clues as to what is going on ( plugins=undefined ), please review
#2878006: Blank media popup after upgrade to 7.x-2.0 or later

karamveersingh’s picture

hello all,

I upgraded media module from "Media 7.x-2.0" version To "Media 7.x-2.2" and everything configured perfectly but unfortunately faces issue with missing square_thumbnail image style.

I go-through above all thread and some comments matched with my problem -> https://www.drupal.org/node/2486599#comment-10852494
https://www.drupal.org/node/2486599#comment-11306413

Just want to know do we need to create required image-style i.e. square_thumbnail manually after setup the media module,please confirm.

joseph.olstad’s picture

Title: Broken images in media browser and file/thumbnail » missing square_thumbnail causes Broken images in media browser and file/thumbnail
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Status: Needs review » Needs work
joseph.olstad’s picture

  • Sagar Ramgade authored 3229f0e on 7.x-3.x
    Issue #2486599 by Sagar Ramgade, joseph.olstad: missing square_thumbnail...

  • Sagar Ramgade authored 78ae72d on 7.x-2.x
    Issue #2486599 by Sagar Ramgade, joseph.olstad: missing square_thumbnail...
joseph.olstad’s picture

Version: 7.x-2.0-alpha4 » 7.x-2.x-dev
Status: Needs work » Fixed

There was a patch there the whole time, of course no one could figure out how to use it because they had already upgraded and the hook update had gone, so I added a new hook update that calls the fixed 7211 update.
see commit changes.
fixed in 7.x-2.x dev and 7.x-3.x dev
if you have this problem, upgrade and then update.php or drush updb -y

karamveersingh’s picture

FileSize
17.89 KB

@joseph.olstad thanks for your messages, we upgraded media form 7.x-2.0 To 7.x-2.3 and in this version my queries are cleared.
In update.php its prompted required image-style (square_thumbnail) which is correct.
Going to confirm 7.x-2.3 fixed the missing image style issue,see attachment.

joseph.olstad’s picture

awesome, yes, sorry it took so long to get this fixed, someone had already posted a patch and I missed it.

here's the original patch by Sagar Ramgade

all I did was add his patch, then re-call the update 7211 in a new update (7227)

rick_p’s picture

I just did a fresh D8 install, installed all the required modules and did all the configuration and still got the broken (missing) thumbnail in the Media List. I tried adding the square thumbnail (square_thumbnail) and that didn't resolve the issue. This is what all images get for a thumbnail in the Media List...

/files/styles/thumbnail/public/media-icons/generic/image.png

If there is a working patch for this, is there any reason why it hasn't been added to a stable release so people can avoid the headaches?

rick_p’s picture

For Drupal 8 you must also install these modules:

Crop API
ImageWidgetCrop
Media entity crop

After those are installed, make sure your media bundle for images is set to "image" for the Crop Configuration.

Best, Rick

joseph.olstad’s picture

After upgrading make sure to run drush updb
Or
update.php

Do so, so that the image style square_thumbnail gets created

  • Sagar Ramgade authored 3229f0e on 7.x-2.x
    Issue #2486599 by Sagar Ramgade, joseph.olstad: missing square_thumbnail...

  • Sagar Ramgade authored 78ae72d on 7.x-3.x
    Issue #2486599 by Sagar Ramgade, joseph.olstad: missing square_thumbnail...
Jens Peter’s picture

Status: Fixed » Active

I just updated to 2.8 and ran into this issue.
I am not able to create the square_thumbnail.

After the update.php was run I got this:
Update #7227
Failed: PDOException: SQLSTATE[HY000]: General error: 1364 Field 'isid' doesn't have a default value: INSERT INTO {image_styles} (name, label) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => square_thumbnail [:db_insert_placeholder_1] => square_thumbnail ) in drupal_write_record() (line 7383 of /var/www/xxxxxxx/includes/common.inc).

If I try to make the square_thumbnail now it get the following:
PDOException: SQLSTATE[HY000]: General error: 1364 Field 'isid' doesn't have a default value: INSERT INTO {image_styles} (name, label) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1); Array ( [:db_insert_placeholder_0] => square_thumbnail [:db_insert_placeholder_1] => square_thumbnail ) in drupal_write_record() (line 7383 of /var/www/xxxxxx/includes/common.inc).

The last update of the module is done on June 16, so I assume the patches above is done?
Hope someone is able to help on this one.

joseph.olstad’s picture

Status: Active » Postponed (maintainer needs more info)

The above reported error is from core. What database driver are you using? Postgresql ? sqlite? or other ? I have never seen this error before. Prefer that you open a new support issue for this.

Jens Peter’s picture

New issue made here https://www.drupal.org/node/2889666 regarding my post before.
Thank you Joseph

joseph.olstad’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

VJ The Drupal Techie’s picture

Hi

Sometimes, the form_state variable declaration at function parameters will cause the issue.

Wrong:
function custom_new_form($form, $form_state) {
}

Correct:
function custom_new_form($form, &$form_state) {
}

Thanks

JeffMattson’s picture

After updating the media module to 7.x-2.19, thumbnails where no longer showing for uploading images and after checking the square_thumbnail folder did not contain the new thumbnail image.

The fix was to disable and re-enable the module after updating.

wturrell’s picture

I'm updating an inherited site that was on 7.x-1.6 and it also disappeared on upgrading to 2.19.

Not sure if this helps, but I rolled the database back and ran it again.
The web UI shows 7211 as a pending update.
My cache_image table is also empty before it starts.
I don't see anything in php_errors.log when the update runs.
I couldn't figure out a way to get an xdebug breakpoint to trigger for the actual update and unfortunately this site doesn't have a working Drush install so I can't poke around in PHP.

Probably a bit late for this now, but I think it would be useful if the media_update_7211() returned a message according to what actually happened (rather than the same regardless) - ie. if it was present before or a thumbnail was added.

joseph.olstad’s picture

This may have been due to a recent commit in a recent release

If you still have your database backup, try instead of upgrading to 7.x-2.19 first
upgrade to 7.x-2.12 first and THEN upgrade to 7.x-2.1
9

if this resolve the issue, let us know right away so we can fix it, I think there was a recent commit in 7.x-2.17 that may have affected this update hook.

my appologies

joseph.olstad’s picture

I had a look at recent code changes,

My appologies

try this:

reverse this commit OR upgrade first to 7.x-2.15 before upgrading to 7.x-2.19 , unfortunately you'd have to redo this with a backup copy of your schema
#2841742: Media WYSIWYG View Mode configuration lost after media_wysiwyg_update_7205

try upgrade again using your db backup, it should work.

Really choked here about this, someone reported an issue, but apparently it breaks this fix, I will have to revert that commit, for now, run the patch in reverse

related regression caused by : #2841742: Media WYSIWYG View Mode configuration lost after media_wysiwyg_update_7205

wturrell’s picture

Hello.

Hmm - that doesn't seem to have worked for me: on going to 7.x-2.15 I see all the updates listed (7211 + 7227), including the 7211 return message afterwards, but no square_thumbnail is added to image_styles, it vanishes from the admin page, and then when applying 2.19 obviously there are no more pending updates.

However this is something of an odd site, so don't rush to roll back changes just on my account (and I can obviously work around it).

To clarify, the DB I'm restoring *from*:

- doesn't have a square_thumbnail in its image_styles table
- *does* display square_thumbnail on admin (with the 180x180 legacy size)
- clearing the cache doesn't get rid of it when still running 7.x-1.6
- the cache_image table was already empty when before I started

joseph.olstad’s picture

ok, as a workaround
If the square_thumbnail image style is missing, add it manually in the core image styles. I believe set it to 180x180 pixels

joseph.olstad’s picture

OR , try as jeffreysmattson says
disable and re-enable the module after updating.

museumboy’s picture

This is also broken for me, but it only applies to PNG files. The JPGs are all fine.