Description

This module generates a histogram for images in nodes much like what you may be familiar looking at in Adobe Photoshop or in your camera.

Project page

https://drupal.org/sandbox/matthewmessmer/2184823

Git

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/matthewmessmer/2184823.git histogram

Comments

PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

mehul.shah’s picture

There are some warnings reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxmatthewmessmer2184823git

pijus’s picture

In histogram.php -
Line 85 and 89: Functions should be called with no spaces between the function name and opening parentheses.

or die ("Cannot Initialize new GD image stream");
or die ("Cannot Initialize new GD image stream");

See the coding standard - https://drupal.org/coding-standards#functcall

matthewmessmer’s picture

@mehul.shah

I saw those errors and they are a result of commenting out lines of code that before were resulting in unused variables. In the future, I am planning to use that code to extend some of the functionality. Does anyone have a suggestion on what is the best practice in this case?

If I uncomment the code, the same automated review tool shows different errors for unused variables.
When commented, some of the lines are over 80 characters long and this produces errors.

I suppose I could just make a different dev branch with that code and then remove it from the stable branch, is that the suggested course of action?

eft’s picture

Matthew,

Interesting looking module. This my first project review so bear that in mind :)

  • On the project page you might want to provide some use cases.
  • Does your module only support JPEG image types? (i.e. your use of imagecreatefromjpeg in your histogram_make_histogram function). If so, should warn users in help file and on project page.
  • I don't think you need to add field_ui in the requirements section of the README.txt. given that it is enabled in standard D7 installations.
  • I would only display the help text via the help menu and not also on the config page as you have it currently set up.
  • The help text could use some sub headings for the pages it applies to (ie config, manage fields, node add/edit etc.).
  • What effect does the choice of configured bundles have on the function on the module? The widget still seems to be available in bundles that have not been enabled to work with the module.
  • When updating nodes with the histogram widget the option to regenerate the histogram should be more obvious. Users (well at least I did) tend to miss or gloss over options and expect it to work with default settings.
  • Try multi-line PHP comments if you want to appease code sniffer. You probably want to add an explanation for why you commented out code in the first place. Maybe add a @todo tag anyway.

Hope this helps

mehul.shah’s picture

Hi machostache,
yes you have to move that commented part to dev branch, and release only stable version for now.

webmorozov’s picture

Status: Needs review » Needs work

Hello, machostache!

Thanks for an awesome idea and module. It might be useful in some cases.
I have reviewed the module and I find some minor issues with it. But It works quite well and I can see possibilities on how it can be extended in the future.

I think the module can be promoted to full project, after small fixes:

1) histogram.php should be renamed to histogram.inc. php files by default executable, so it not safe.

2) Use theme_image in theme_histogram_formatter_default. Maybe somebody want to add additional class for your image or etc...

/**
 * Histogram theme formatter.
 */
function theme_histogram_formatter_default($item) {

  $output = '';
  $output .= '<img class="histogram" src="';
  $output .= url($item['name']);
  $output .= '" >';

  return $output;
}

3) Why you work only with nodes? We should provide functions for all entities. For now you can describe those limitations and fix it in the future.
if ($instance['entity_type'] == 'node') {

4) set_time_limit(50000) it's not great solution because we will have problems with performance. If it is a very difficult operation (need a lot of time) we should move it to the background (cron).

/**
 * Makes PNG file histogram.
 */
function histogram_make_histogram($image, $color = "#000000", $force_bw = FALSE, $hist_type = 1, $hist_width = 256) {
  set_time_limit(50000);
  if (!isset($image)) {
    drupal_set_message(t('An error occurred and processing did not complete.'), 'error');
  }

5) Please remove comments:

  // $histogram_r_compiled = array();
  // $histogram_g_compiled = array();
  // $histogram_b_compiled = array();

6) On uninstall process you should remove all variables that you created before:
foreach (variable_get('histogram_nodetypes', array()) as $type) {

7) I found that png, gif files not work because you use only $img = imagecreatefromjpeg($source_file).
Could you handle other cases imagecreatefrompng(), imagecreatefromgif()?

Now about global approach:
I want to know why you use additional settings form admin/config/media/histogram/settings? I didn't get it.

I add field to that content type, so I want to render histogram. Why I should set double settings "Select nodetypes which should be enabled for histogram generation." here admin/config/media/histogram/settings.

In my opinion we didn't need create new field type. Why user should each time select "Histogram Type", "Force Single Channel Histogram" for each node? Are you realy need that fields?
I think you can just implement field formatter for standart image fields:
1) Move that settings to field formatter form
2) "Histogram Type", "Force Single Channel Histogram" it just VIEW, but not buisness logic.
3) We can just implement 2 different View Mode for that node and output "Stacked" or "Combined" histogram.

Other approach implement new image effect (image style effect) hook_image_effect_info:
1) Implement your settings in effect form
2) if you want you can create two image styles with different settings:
"Stacked"
"Combined"
"Image overlay (image + histogram)"
etc.
3) Image style will handle and store all files! You just implement effect
4) Apply that image style to standard image field. Image -> effect -> call your histogram_make_histogram with image as argument (see) -> your calculate histogram and override $image->resource.

As result you can implement histogram for all Entities, Multiple fields, etc. in more common drupal way.

Altogether a great module and it's working now.

This is just my thoughts on how it could be improved... If you want I can help you with it.

Best regards,
WebMorozov

matthewmessmer’s picture

@webmorozov and everyone else

Thank you for your suggestions and comments. I have tried to fix all the outstanding issues with the module.

1) The file has been renamed to histogram.inc

2) I'm using theme_image now.

3) I agree that it work with all entity types, but I think this would require some more testing. For now, I have updated the documentation to note this limitation as you suggested.

4) The set_time_limit has been removed. I haven't found the script to take that much time to run, and it doesn't run every time the node is saved anyway.

5) I've removed all the unused variables.

6) The settings form at admin/config/media/histogram/settings was no longer serving any purpose so I removed it. So these variables are no longer set.

7) I changed this so that any .gif .jpeg .jpg or .png file should work now. I've updated the documentation to mention this.

One reason I created the module the way I did is that I wanted people to be able to specify default behavior for a particular content type (the field defaults for background color, histogram type) but be able to override this on a node by node basis. I'm not sure if this functionality could be preserved with the image style, could it?

matthewmessmer’s picture

Status: Needs work » Needs review
gbisht’s picture

Status: Needs review » Needs work

Hi,

For the 2nd point, you are calling theme function directly. For best practice instead of theme_image($variables) you should use theme('image', $variables).

matthewmessmer’s picture

Status: Needs work » Needs review

@gulab.bisht

Thanks for the best practice tip. I've committed the change you suggested.

olivierg’s picture

Change is ok and the module works.

But when i generate a histo, i have 2 warnings:
Warning: Division by zero in _histogram_make_histogram() (line 115 of C:\wamp\www\neurones_import\sites\all\modules\histogram\histogram.inc).
Warning: Division by zero in _histogram_make_histogram() (line 116 of C:\wamp\www\neurones_import\sites\all\modules\histogram\histogram.inc).

The code in function _histogram_make_histogram() is too long, maybe can you create sub functions ?

deekayen’s picture

Status: Needs review » Fixed

I'm approving this live in the mentor booth at DrupalCon.

klausi’s picture

Thanks for the review deekayen! Usually we only approve RTBC applications that have been verified by an additional pair of eyes.

And you should also post our nice welcome message from https://groups.drupal.org/node/184389#promote :

Thanks for your contribution, machostache!

deekayen updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

deekayen’s picture

@klausi, yes, I understand there should be more eyes and I counted myself as those extra eyes. I did a code review in person, gave him my commentary, promoted him, and stuffed the remaining issues into the project issue queue. I didn't see any reason to keep him waiting any longer.

Status: Fixed » Closed (fixed)

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