• Is there any way to use your plugin to specify the location and crop lines of square thumbnails? If not, have you ever considered adding this? Basically, it would be a per-image ability to select the exact square you want used for your square thumbnails. When regenerating images, it would use the standard “Thumbnail” image size, but base it on a section of the image chosen by the user. As with most sites, I have some images where the main subject of the picture is off center so the auto-generated thumbnails look really bad. They either cut off or cut in half the main subject leaving a terrible composition. If somehow there was an editor, usable separately for each image, to let the user visually “drag a square” over an image to specify “this is the section I want to use” and then regeneration could simply crop out that square and size it to the standard “Thumbnail” size.

    If you can’t do this, is there any hook you provide that might allow such a thing (assuming somehow separately we’ve stored the user selection data)? It would need to pass some bit of data to identify the current image being resized…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor viper007bond

    (@viper007bond)

    This is outside the scope of my plugin, but there are plugins out there that allow you to control the cropping. Unfortunately a lot of them (or all of them?) don’t account for my plugin calling the core WordPress thumbnailing functions again.

    Since my plugin doesn’t use any custom code to do the actual thumbnail generation, all those cropping plugins need to do is hook into those normal WordPress functions and make sure that their custom crop location is used when generating thumbnails for an image. And frankly if I were to write such a plugin, it’s how I would do it anyway so that I didn’t have to write my own thumbnailing code.

    Maybe one of these days I need to write a cropping plugin that does things the “right way”…

    Thread Starter kairei

    (@kairei)

    Ok, so if I’m understanding correctly, it sounds like the hook I was wondering if you might provide isn’t necessary. During regeneration, you call standard WordPress thumbnail functions (not sure what they are but assume they are documented) and WP provides hooks to those, so one just needs to plug into the normal WP hooks to do the custom thumbnail logic and that will work on initial thumb creation and when your plugin is run. Is that right? Thanks!

    Plugin Contributor viper007bond

    (@viper007bond)

    Correct!

    The poorly named wp_generate_attachment_metadata() is what I call which will create the thumbnails:

    https://core.trac.www.ads-software.com/browser/tags/4.9/src/wp-admin/includes/image.php#L74

    The actual resizing is triggered here:

    https://core.trac.www.ads-software.com/browser/tags/4.9/src/wp-admin/includes/image.php#L135

    However there aren’t the hooks I thought there were in the actual image manipulation classes:

    GD: https://core.trac.www.ads-software.com/browser/tags/4.9/src/wp-includes/class-wp-image-editor-gd.php#L193
    Imagick: https://core.trac.www.ads-software.com/browser/tags/4.9/src/wp-includes/class-wp-image-editor-imagick.php#L408

    So hooking into the end of wp_generate_attachment_metadata() with the wp_generate_attachment_metadata filter is probably the only way to do it, overwriting the already generated thumbnail that WordPress made. The built-in image manipulation libraries mentioned above can do it, so it’s just a matter of calling crop() with the right coordinates and size.

    Even if I added a new hook to my plugin, it wouldn’t be more useful of a hook. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Specifying location and size of square thumbnails’ is closed to new replies.