This patch splits the image api from the gd2 image manipulation functions to start with.
Only api functions remain inside image.inc, and image.gd.toolkit.inc should be copied from the next comment.

To review:
- Apply the patch as you normally do;
- copy the new image.gd.toolkit.inc into your includes directory;

Try to upload some images and see if it works... :-) (It does here at least)

The underlying thought are to extend the possibilities of the image api, tmo anipulate your images on the fly through a drupal UI after uploading them.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Stefan Nagtegaal’s picture

FileSize
4.06 KB

Err...

It was image.gd.inc instead of image.gd.toolkit.inc..

So, in hort to review you do:
- apply the patch;
- copy image.gd.inc.patch into includes/ and rename it to image.gd.inc;

that's all, enjoy!

Stefan Nagtegaal’s picture

FileSize
5.62 KB

New patch, now everything is in the patch itself including the new added image.gd.inc file.

To review:
- apply the patch;

And that's nearly it. It's a pretty trivial patch, nothing special. But there is more to come when this hits the trunk..

ChrisKennedy’s picture

It appears that the patch in #3 does not include the new file - I think you need to put the -N flag before your -F^f.

Stefan Nagtegaal’s picture

FileSize
10.25 KB

Another attaempt to make the right patch..

this should do it! :-)

Stefan Nagtegaal’s picture

the patch before had a bug when used in a new installation of drupal.

This one fixes that.

Ready for review! :-)

Gurpartap Singh’s picture

The patch is straight forward, but:

  function image_gd_info() {
    return array('name' => 'gd', 'title' => 'Build-in GD2 toolkit.');
  }

You could change it to: 'title' => t('Built-in GD2 toolkit')

  if ($toolkit = variable_get('image_toolkit', 'gd')) {
    drupal_set_message("De huidige toolkit is $toolkit");
    include_once './includes/image.'. $toolkit .'.inc';
  }

Could just be changed to:

  $toolkit = variable_get('image_toolkit', 'gd')) {
  include_once './includes/image.'. $toolkit .'.inc';

Removed the message; and the if () check, because it's always going to have a value, either the one set by the user, or the default i.e. 'gd'.

Some more features could be introduced so that contributed modules can make use of introducing new libraries, that can be a separate patch though.

dikini’s picture

simple patch. improves consistency. Allows cleaner imagemagic integration. works.

drewish’s picture

Humm, I couldn't apply the patch...

patching file includes/image.gd.inc
patching file includes/image.inc
patch unexpectedly ends in middle of line
patch: **** malformed patch at line 385:

I'll give it a try on another machine.

drewish’s picture

FileSize
9.75 KB

I think this is an excellent idea. It makes for a much cleaner interface.

I made most of the changes Gurpartap Singh pointed out but ended up restoring a good chunk of the original image_get_toolkit() function. The primary reason being that users can delete the toolkit files. I get bug reports on the image module from users who'd deleted the imagemagik toolkit and couldn't get the setting to switch back. If the file's missing there's no toolkit.

Stefan Nagtegaal’s picture

FileSize
10.11 KB

Okay, here is another updated patch which includes above concerns, but instead of having an image.gd.inc file, we now have a image.gd2.inc file (because of backwards compatibility and it's GD2 not GD).

There is no update/upgrade path needed. This patch works really well, and I encourage people to review this so it get's committed. After that I'll try to add some new functionality to the image api, so our image handling will be a little better.

drewish’s picture

Steef, I'm unclear why you changed the name from gd to gd2... It is more accurate but you will need an update to change the image_toolkit variable's value from gd to gd2.

Stefan Nagtegaal’s picture

Forget my last patch.. After discussing with Drewish, his patch is preferable above mine..
We tested this throughly, and after one other review this should be RTBC..

For everybody who's interested, http://drupal.org/node/148346#comment-254671 (drewish followup #9) is the patch to apply and test..

drewish’s picture

okay so steef and i talked on IRC and decided that the patch on #9 is the way to go.

webchick’s picture

Status: Needs review » Reviewed & tested by the community

Wow, this is really one of those "You mean it didn't already work like this?!" patches. It makes far more sense for gd-specific functions to be in image.gd.inc than in image.inc. +1.

Functionality-wise, I tested the two places in core where the image API is called: user pictures and upload.module (when max definitions are specified). In both cases, everything worked as expected.

Patch #9 is RTBC.

sime’s picture

/subscribing (late)

Stefan Nagtegaal’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

This patch is superseeded by "Improve image-api: Image toolkits should be implemented as modules", which gives us much more control, flexibility and a cleaner implementation/code.

Marking this one as "Duplicate"

Stefan Nagtegaal’s picture

Title: Split image-api and GD2 image manipulation functions » Let image.inc be an api, and move GD toolkit code into image.gd.inc
Category: task » bug
Status: Closed (duplicate) » Reviewed & tested by the community
FileSize
10.48 KB

Well, re-opening this issue because Dries rehected this issue to get in.
Let's make this right now...

Updated patch to apply against HEAD. Setting status back to RTBC as that was it's current state before I marked it as a duplicate.

In short what the patch does:
- removes cruft from the image api;
- properly adds t()'s to all translatable messages;
- refactored image.inc to be more like an api, so I moved all GD toolkit specific code to image.gd.inc;

Please get this in...

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Reviewed the code:

- The gd file should have a @file comment, it does not have this phpdoc tag there now
- The image_gd_info() function could use a short explanation. Is it a hook implementation?
- The t() change I see with the watdog() call is definitely not right. Watchdog() calls *should not* have t()-ed strings (possibly except their last link parameter) in Drupal 6, as they are localized on display, not on logging.

Otherwise this seems like a logical code cleanup (so IMHO it is on track to be committed) but I don't see how this provides any new possibilities, unlike how others pointed out.

Stefan Nagtegaal’s picture

Status: Needs work » Needs review
FileSize
10.99 KB

@Gabor: First of all, this patch do not - in any way - add new possibilities. Unfortunatly the patch that does introduced toolkits as modules (and *much* more flexibility to work with), ended up to not be committed for drupal 6. So, I'm trying to pave the way for a nice and clean API in D6, which could be used as a base to implement more image manipulation features in the future.

I updated the patch:
- added @file php doc, which seem to have been missed;
- added a short but descriptive message to image_gd_info();
- and changed the t() calls around the watchdog messages (I missed it when this got committed, sorry);

Now, we are ready for review again! :-) Pls commit when you like, so we can further improve things step by step...

drewish’s picture

FileSize
17.66 KB

Since there's a chance that this might get committed, I've gone through and modified all the comments to follow the coding standards.

I made one small change to image_rotate(). It now lets you pass a background color to the toolkit. The GD toolkit has always accepted the parameter which defaulted to 0.

Gábor Hojtsy’s picture

@Stefan: well, dikini pointed out that this allows cleaner imagemagic integration, which I don't see. Anyway, this does not make this patch better or worse ;)

Seems like the latest patch has file comments misplaced. It has a GD2 file comment on top of image.inc, and a generic one on top of gd.inc.

Let's get reviews on the patch, so we have more eyes seeing it works, and I can commit it.

Stefan Nagtegaal’s picture

FileSize
12.75 KB

I swapped the comments as suggested by Goba.
Furthermore this is working very, very well.

Let's get someone else to review this, and let him (or her) set this RTBC. :-)

Stefan Nagtegaal’s picture

FileSize
17.85 KB

** New patch file, which does include the image.gd.inc file */

I swapped the comments as suggested by Goba.
Furthermore this is working very, very well.

Let's get someone else to review this, and let him (or her) set this RTBC. :-)

Stefan Nagtegaal’s picture

Status: Needs review » Reviewed & tested by the community

This is ready. It is tested pretty intensively by myself and I could not find anything that isn't working, or broken.

Please get this in..

Dries’s picture

Status: Reviewed & tested by the community » Needs work

This patch seems to introduce API changes (i.e. addition of background color) and should probably be postponed to D7 instead? Please motivate this change, and I'll consider to commit it.

Please rename $bg_color to $background.

drewish’s picture

Status: Needs work » Needs review
FileSize
17.53 KB

Dries, technically, it is a change. All it does though is to correct one annoying wart in the image API. It does so by adding an additional, optional, parameter that defaults to its current behavior.

image_gd_rotate() already accepts the background color parameter but image_rotate() isn't providing anything to it. So if you wanted a white background on a rotation you had to callimage_toolkit_invoke('rotate', ...)); and pass it in yourself.

Stefan Nagtegaal’s picture

@Dries: there is no place in contrib, or core where image_toolkit_invoke('rotate', $arguments) is used. So, we aren't breaking anything.

@drewish: thanks for updating this patch at my absense, I really appreciate you time, effort and thinking which helped me a lot while building the patch.

Dries’s picture

Status: Needs review » Needs work

I'm OK with committing this patch for D6 -- it doesn't break anything. However, I'd like to see us add some code comments to the top of image.inc, and maybe extend the code comments on top of image.gd2.inc to reference image.inc.

At the top of image.inc, it would be good to explain the purpose of this file, and the basic design of the image API. Specifically, it is worth explaining why it is important to use Drupal's API rather than using PHP's functions directly. Why would you _not_ want to use GD2 -- it's part of a standard PHP installation. Explain why other toolkits might be better?

It's also useful to explain that one can swap in different image backends, how that is done, what backends are supported out of the box. For developers, it's really useful to know this all works from a high-level point of view. Furthermore, it might also be useful to explain certain limitations -- can I have more than one active backend at the same time?

If we can add one or two paragraphs of text to the top of image.inc, then this makes for a good commit.

Thanks.

drewish’s picture

FileSize
12.31 KB

first for anyone who's testing at home, here's an imagemagick toolkit that works with D6. re-roll to follow.

drewish’s picture

Status: Needs work » Needs review
FileSize
18.87 KB

poked through the database.inc to get an idea of how to add a @defgroup. i haven't run it through the api.module but it looks like it should be alright.

when you know how something works docs are hard to write, i never know what questions to answer. hopefully someone can take a look at those and make sure they make sense.

Dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Good job.

drewish’s picture

Status: Fixed » Reviewed & tested by the community
FileSize
2.14 KB

It looks like you only committed part of the patch... if you didn't like my docs you could have just said so ;)

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)