The Drupal 6 version of ImageCache supports "default presets", which allows modules to provide presets through hook_imagecache_default_presets(). Unfortunately this functionality was added after the initial patches to port ImageCache to Image module in core, so this functionality was not included in the core version.

Besides the feature regression, providing default styles has immense value. In Drupal 6, we found that a lot of modules ship with default presets. Ubercart for example comes with "uc_thumbnail", "uc_preview", and a few others. I think this is largely because there are no "core" presets that modules can count on. The end result is that every module that needs a preset makes another new one, even if there are already several ones that might have worked just as well.

To prevent the rampant recreation of the nearly identical styles by many different modules, we should include a set of default sizes that modules can depend on being there. Taking a page from WordPress, I've named these styles "thumbnail", "medium", and "large". WordPress defaults these sizes to 150x150, 300x300, and 1024x600. Our sizes default to:

- 100x100 (thumbnail)
- 220x220 (medium)
- 640x640 (large)

Of course these styles may be adjusted to any size the user wants, but the names may not be changed (since otherwise modules could not depend on these names). The ability to provide defaults styles such as this will help both new users and developers. The users will get a few styles "out-of-box" and developers don't have to worry about redefining new styles everywhere they need a "medium" or "large" image.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Tagging.

Status: Needs review » Needs work

The last submitted patch failed testing.

quicksketch’s picture

Status: Needs work » Needs review
FileSize
22.6 KB

I removed a test from this version of the patch, since now that we don't include a database style in the default installation profile, it didn't have anything useful to retrieve. However, the test provided no real value anyway, since image effects need to be properly stored and retrieved in the ImageAdminStylesUnitTest test anyway.

quicksketch’s picture

FileSize
22.18 KB

Shortening up docs a bit, increasing consistency of the "Revert" terminology.

Dries’s picture

No tests?

quicksketch’s picture

Thanks for having a look Dries, I'll post a revised version with tests. Anyone else, please continue to try this patch out, since it's functionally complete.

quicksketch’s picture

FileSize
24.63 KB

Added a test to do the following:

- Check that default styles are not editable
- Check that default styles generate images properly
- Override a default style
- Check that overridden styles may have effects added
- Check that overridden styles may not have their names changed
- Check that overridden styles generate images properly
- Revert an overridden style
- Check that the default effects are restored

Status: Needs review » Needs work

The last submitted patch failed testing.

quicksketch’s picture

Status: Needs work » Needs review

My local doesn't have any errors when running these same tests, maybe a different testing slave will help?

quicksketch’s picture

FileSize
25.59 KB

Oh, no I just forgot to include the changes to the default.profile. Here we are.

WorldFallz’s picture

Status: Needs review » Needs work
FileSize
10.75 KB

Tested with a fresh co from head. Patch applied fine, but I received the following notices:

* Notice: Undefined index: storage in image_style_form() (line 43 of /home/grumble/public_html/head/modules/image/image.admin.inc).
* Notice: Undefined index: storage in image_style_form() (line 62 of /home/grumble/public_html/head/modules/image/image.admin.inc).

Some weirdness-- i originally only saw a 'thumbnail' style and received the above notices. Once I manually created a style the notices went away and medium and large styles styles appeared in addition to thumbnail and the one I created.

Image style table after adding my style:

image-styles.png

Gonna finish testing, but thought you might want to see this right away.

WorldFallz’s picture

Status: Needs work » Needs review

seem we crossposted

quicksketch’s picture

Tested with a fresh co from head. Patch applied fine, but I received the following notices:

It sounds like you updated an existing site with new code but didn't re-install from a fresh copy. The notices you received were caused by the cached copy of the list of styles being stored in the database. It also explains why "medium" and "large" weren't available until you editing an existing style (which cleared this cache).

EDIT: Oh, or it's actually likely that this was just caused by my bad patch which didn't include the install profile changes. Sorry about that. :-(

WorldFallz’s picture

Ok, tried again with the current patch and another fresh head:

One offset:
Hunk #1 succeeded at 173 (offset 20 lines)

Notices and weirdness are gone.

Not sure what else to test so going with the items in #7:

- Check that default styles are not editable
they are-- there's an edit link and they can be overridden and reverted.

- Check that default styles generate images properly
check

- Override a default style
check

- Check that overridden styles may have effects added
check

- Check that overridden styles may not have their names changed
couldn't figure out how to check this

- Check that overridden styles generate images properly
check

- Revert an overridden style
check

- Check that the default effects are restored
check

WorldFallz’s picture

@13 -- it was a fresh checkout, but installed before I patched. In any case, weirdness is gone.

WorldFallz’s picture

BTW image/imagefield/imagecache in core is f'in AMAZING! Nice nice nice job!

quicksketch’s picture

FileSize
12.02 KB

- Check that overridden styles may not have their names changed
couldn't figure out how to check this

This just means that when you visit admin/config/media/image-styles/edit/thumbnail you shouldn't be able to change the name of the style (since module's likely depend on the existence of any default/overridden style). See screenshot.

(Thanks for the reviews!)

WorldFallz’s picture

- Check that overridden styles may not have their names changed
couldn't figure out how to check this

I'm an idiot-- they're not so 'check' here also.

WorldFallz’s picture

One wrinkle-- seems to be a problem with added styles not rendering at all. Playing around with it now.

WorldFallz’s picture

Unfortunately I confirmed it-- no manually added styles render at all. I created a dupe of the 'medium' style and it doesn't render at all. I added a bunch of other manually styles and they won't render either.

WorldFallz’s picture

Per our discussion in irc, this problem exists without the patch as well-- i just confirmed it. So the patch itself seems fine.

grendzy’s picture

There are no breadcrumbs on /admin/config/media/image-styles/edit/thumbnail.

"Storage" (Overridden / Default / Normal) is confusing – I thought this was describing the storage backend for the image files themselves. (ooooh! configurable storage! Does this mean I can put my images on S3?)

Confirmed WorldFallz report in #19 - user-defined styles don't display at all.

Coder reports quite a few style issues, mostly tabs it seems (Edit: nevermind, these seem to be false positives, coder doesn't like indented phpdocs).

WorldFallz’s picture

meh-- i can't get coder to work at all lately, lol. And I see what you mean about 'storage" -- maybe status or type?

WorldFallz’s picture

Status: Needs review » Needs work

talk about a drupal wtf, i didn't change the status, lol.

quicksketch’s picture

Status: Needs work » Needs review

Here's a patch for solving the problem WorldFallz has been describing. Though like she states, it's not related to this patch. #604650: New image styles are not usable as formatters

WorldFallz’s picture

ok, retested patch from 10 with #604650: New image styles are not usable as formatters as well -- applies with offsets (obviously), and seems to work fine!

quicksketch’s picture

There are no breadcrumbs on /admin/config/media/image-styles/edit/thumbnail.

This problem exists all over the place right now. I had been working hard on #483614: Better breadcrumbs for callbacks, dynamic paths, tabs to fix this.

"Storage" (Overridden / Default / Normal) is confusing – I thought this was describing the storage backend for the image files themselves. (ooooh! configurable storage! Does this mean I can put my images on S3?)

I think "storage" is a fine internal name since it'll be clear that it is part of the style itself ($style['storage']) and it'll line up with existing paradigms for normal/default/override within modules like Panels, Views, ImageCache, Flag, etc. However I completely agree that this is a confusing term for end-users in regards to images. Any suggestions for what to label that column?

quicksketch’s picture

How does the word "Settings" sit with you guys? I'd like to keep existing internal terminology and just rename the labels shown to the end user. How do these terms sound?

Settings
---------
Custom
Overridden
Default
grendzy’s picture

The labels in #28 sound good, thanks!

quicksketch’s picture

FileSize
25.59 KB

Now using the labels from #28.

WorldFallz’s picture

Sounds good to me-- did anything else in the patch change?

WorldFallz’s picture

/me trys to kick the bot...

quicksketch’s picture

No other changes in #30 besides label changes, tests passing, do we need anything else?

grendzy’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs documentation

This looks solid to me. I also like that this (indirectly) makes image styles "exportable". Tagging so we don't forget to add the API docs for hook_image_default_styles.

arianek’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs documentation

Patch applied:

Hunk #1 succeeded at 173 (offset 20 lines).

EEEEEK.

so, i am WSOD'ing over here. i recreated it twice (totally wiped the install and set up same settings and got it again), and it doesn't happen before adding the patch and adding the config for image field. *but* i am not 100% if it is from the patch, as tha_sun was saying that the same thing came up with radio button field.

anyway, so if anyone wants to try and duplicate this, here are screenshots of all the settings:

- initial field config page: http://skitch.com/arianek/ndg6j/article-localhost.drupal7

- second longer config page (sorry it's in parts!): 1) http://skitch.com/arianek/ndg6q/imageswow--localhost.drupal7 2) http://skitch.com/arianek/ndg6x/imageswow--localhost.drupal7 3) http://skitch.com/arianek/ndg6t/imageswow--localhost.drupal7

i'm going to poke at this some more and see if i can narrow down what's causing it, but not feeling terribly hopeful! and i am not gonna be able to do much for testing it if i can't get the WSOD narrowed down! thought i should post this right away tho... hope it's not really caused by the patch!

arianek’s picture

Issue tags: +Needs documentation

re-adding the needs doc tag (i overwrote that)

arianek’s picture

ps. just removed the image field that i had added to article and the WSOD went away on the node/add page - it's gotta be one of the config settings for the field...

arianek’s picture

pps. just added an image field without changing any of the default settings and DO get the WSOD. then reverted the patch and added an image field without changing defaults and still get the WSOD. deleted the image field altogether, and no WSOD on node add. i'm stumped.

quicksketch’s picture

Status: Needs review » Reviewed & tested by the community

I feel a bit pushy (hey today is code freeze) but I can't reproduce any such whitescreens. Like arianek said though, it's not actually caused by this patch, since the sandbox is getting a white screen on just a default image field. Since it's not related, mind if I put back grendzy's RTBC?

quicksketch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs documentation
FileSize
27.56 KB

Okay, one more patch. Including documentation now.

WorldFallz’s picture

Status: Needs review » Reviewed & tested by the community

Sorry, been a little out of pocket since last night (code freeze of all days, lol)-- but this looks good. Docs made sense to me-- so that's an accomplishment. ;-)

webchick’s picture

Status: Reviewed & tested by the community » Needs work
+++ modules/image/image.module	15 Oct 2009 08:15:32 -0000
@@ -6,6 +6,31 @@
+/**
+ * Image style constant for user presets in the database.
+ */
+define('IMAGE_STORAGE_NORMAL', 1);
+
+/**
+ * Image style constant for user presets that override module-defined presets.
+ */
+define('IMAGE_STORAGE_OVERRIDE', 2);
+
+/**
+ * Image style constant for module-defined presets in code.
+ */
+define('IMAGE_STORAGE_DEFAULT', 4);
+

The one thing I don't like about this is it's *so* close to being a fully-fledged CTools-esque "make defaulty" feature that it seems a shame to tie it to images specifically.

But, there are a couple things:

1. A full blown Export API would be a new feature, and we're well past feature freeze, and it also would be too much to try and cram into this last few days.

2. Nate explicitly does NOT want to provide a "disable" facility for this, so that modules can count on there being things like "thumbnail" available. Without that assurance, there's not much point in this patch since we'll continue to get "style bloat".

+++ modules/image/image.module	15 Oct 2009 08:15:32 -0000
@@ -87,15 +112,27 @@
+    'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE),
@@ -105,6 +142,7 @@
+    'load arguments' => array(5, (string) IMAGE_STORAGE_EDITABLE),

I wanted to know why these were cast to string, and Nate pointed out that it's because otherwise the menu system will interpret them as URL arguments.

+++ modules/image/image.module	15 Oct 2009 08:15:32 -0000
@@ -310,15 +388,44 @@
+      drupal_alter('image_styles', $styles);

I can haz docs or hook_image_styles_alter()?

While Nate works on docs, I'm going to give this a run-through from a UI perspective.

This review is powered by Dreditor.

webchick’s picture

Screenshots of the UI:

Here's the main styles listing. The first three are module-defined, and either are shown as "Default" (meaning they're just as the module designed), "Overridden" (meaning I changed something), or "Custom" (meaning I created it). Overridden styles can be reverted back to the original, custom ones can be deleted. All styles may be edited:

Styles screen

If I edit a default style, I'm taken to a screen with a notice and an "Override defaults" button:

Warning

If I click the button, I get the normal image style interface with a notice at the top that I'm overriding:

Notice

Revert will give me a confirm form:

Revert

This all looks good to me, so no further complaints!

quicksketch’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
28.59 KB

Thanks for the review webchick! Added docs for hook_image_styles_alter().

yoroy’s picture

Status: Reviewed & tested by the community » Needs work

Do it! We discussed how heavily we should promote this override stuff in the UI and agreed to not hold this one up on it.

yoroy’s picture

Status: Needs work » Reviewed & tested by the community

nooo, sorry!

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs documentation

In #drupal, yoroy and Bojhan pointed out that this Default / Overridden / Custom business probably falls under "too much information" for the vast majority of site builders, who are not deploying code through something like SVN, though it is very handy for those who are. I'm on the fence about it, personally. I can see both sides.

As a site builder who *does* follow best practices, this information is really useful so I know which database-related thingies I haven't moved to code yet. Yet, core itself doesn't do anything with this information (there's no image style export functionality) and we also do not do show this type of information in other places in core. For example, with blocks, the way I know whether something is module-provided or custom is whether it has a "remove" link next to it. If so, I added it myself, and I need to move it to code. If not, it's already provided by a module. However, blocks don't have this interim "Overriden" step: they're either module-provided, or custom, and you're stuck with whatever the module gives you.

I think it's worth discussing this more as part of the UI clean-up phase, so I've created #606016: Figure out how best to present overridden/default/custom data as a follow-up.

The UX team confirmed they do not want the patch held up on this issue, so I've committed it to HEAD!

This needs documenting in the module upgrade guide.

arianek’s picture

for the record, i'm just poking at this some more, and totally not getting the same WSOD problem. :-)

jhodgdon’s picture

changing tagging scheme for update guide

jhodgdon’s picture

Status: Needs work » Postponed (maintainer needs more info)

In #47, webchick said this needs documentation in the 6/7 module update guide.

However, I think we are only documenting API changes there, and this seems like an API addition (new hooks to deal with the totally new image module and capability of having image styles, which didn't exist at all in d6 outside of contrib). It may be changing previous functionality from 7.0-alpha-something, but it doesn't change functionality from Drupal 6. I think anyway?

So am I missing something -- what needs to be added to the 6/7 module update guide for this patch/issue?

And by the way, there is no other information in the 6/7 module update guide about the new Image module at all, as far as I can tell...

sun’s picture

Status: Postponed (maintainer needs more info) » Needs work

The ImageCache contrib module feature was introduced after Image module went into core. Way too late for me, and isn't really a core-core upgrade thing, but anyway, I'd simply suggest to go with a streamlined version:

D6:

hook_imagecache_default_presets()

D7:

hook_image_default_styles()

See hook_image_default_styles() for more information.

jhodgdon’s picture

Status: Needs work » Fixed

We don't document contrib -> core upgrades on the core 6/7 page. Or core API additions, for the most part. So if the ImageCache contrib module people want to write a "how to migrate to core" doc page, we can link from http://drupal.org/update/modules/6/7 (at the top, in the section about contrib to core migrations).

But until that happens, I think this core issue is fixed.

Status: Fixed » Closed (fixed)
Issue tags: -Usability, -ImageCacheInCore, -ImageInCore, -Needs documentation updates

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