Skip to main content
added 183 characters in body
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264

Seems that the answer is no...

I've followed the core functions and found a dead-end. And found this post ( How can I make add_image_size() crop from the top? ) where Rarst says:

Intermediate image generation is extremely rigid. Image_resize() keeps it close to code and completely lacks hooks.

But, following the lead of the other answer (from bradt) and the code he published ( Image Crop Position in WordPress ), I think I got it :)

In the function bt_generate_attachment_metadata, I've just modified the call to bt_image_make_intermediate_size including the last parameter $size

$resized = bt_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );

And modified the beggining of the function bt_image_make_intermediate_size as follows:

  • added the $size parameter to the function
  • instead of the default null value to $suffix, a switch to our new suffixes
function bt_image_make_intermediate_size( $file, $width, $height, $crop = false, $size ) {
    if ( $width || $height ) {
        switch($size) {
            case 'thumbnail':
                $suffix = 't';
                break;
            case 'medium':
                $suffix = 'm';
                break;
            case 'large':
                $suffix = 'l';
                break;
            default:
                $suffix = null;
                break;
        }
        $resized_file = bt_image_resize( $file, $width, $height, $crop, $suffix, null, 90 );

Here Here , a copy of the full code with my mods, just for reference.
And the diff from the original.

Much probably, all[2021]
I reviewed the code can be shrank to a bare bone, but this way we getfix the benefit of custom cropped imagesfollowing warnings, :)(h/t @meek2100): two WP functions were deprecated and there's a PHP 8 notice about named parameters.
Gist with the changes annotated on code.

Seems that the answer is no...

I've followed the core functions and found a dead-end. And found this post ( How can I make add_image_size() crop from the top? ) where Rarst says:

Intermediate image generation is extremely rigid. Image_resize() keeps it close to code and completely lacks hooks.

But, following the lead of the other answer (from bradt) and the code he published ( Image Crop Position in WordPress ), I think I got it :)

In the function bt_generate_attachment_metadata, I've just modified the call to bt_image_make_intermediate_size including the last parameter $size

$resized = bt_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );

And modified the beggining of the function bt_image_make_intermediate_size as follows:

  • added the $size parameter to the function
  • instead of the default null value to $suffix, a switch to our new suffixes
function bt_image_make_intermediate_size( $file, $width, $height, $crop = false, $size ) {
    if ( $width || $height ) {
        switch($size) {
            case 'thumbnail':
                $suffix = 't';
                break;
            case 'medium':
                $suffix = 'm';
                break;
            case 'large':
                $suffix = 'l';
                break;
            default:
                $suffix = null;
                break;
        }
        $resized_file = bt_image_resize( $file, $width, $height, $crop, $suffix, null, 90 );

Here, a copy of the full code with my mods, just for reference.
And the diff from the original.

Much probably, all the code can be shrank to a bare bone, but this way we get the benefit of custom cropped images :))

Seems that the answer is no...

I've followed the core functions and found a dead-end. And found this post ( How can I make add_image_size() crop from the top? ) where Rarst says:

Intermediate image generation is extremely rigid. Image_resize() keeps it close to code and completely lacks hooks.

But, following the lead of the other answer (from bradt) and the code he published ( Image Crop Position in WordPress ), I think I got it :)

In the function bt_generate_attachment_metadata, I've just modified the call to bt_image_make_intermediate_size including the last parameter $size

$resized = bt_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );

And modified the beggining of the function bt_image_make_intermediate_size as follows:

  • added the $size parameter to the function
  • instead of the default null value to $suffix, a switch to our new suffixes
function bt_image_make_intermediate_size( $file, $width, $height, $crop = false, $size ) {
    if ( $width || $height ) {
        switch($size) {
            case 'thumbnail':
                $suffix = 't';
                break;
            case 'medium':
                $suffix = 'm';
                break;
            case 'large':
                $suffix = 'l';
                break;
            default:
                $suffix = null;
                break;
        }
        $resized_file = bt_image_resize( $file, $width, $height, $crop, $suffix, null, 90 );

 Here , a copy of the full code with my mods, just for reference.
And the diff from the original.

[2021]
I reviewed the code to fix the following warnings, (h/t @meek2100): two WP functions were deprecated and there's a PHP 8 notice about named parameters.
Gist with the changes annotated on code.

replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

Seems that the answer is no...

I've followed the core functions and found a dead-end. And found this post ( How can I make add_image_size() crop from the top?How can I make add_image_size() crop from the top? ) where RarstRarst says:

Intermediate image generation is extremely rigid. Image_resize() keeps it close to code and completely lacks hooks.

But, following the lead of the other answer (from bradtbradt) and the code he published ( Image Crop Position in WordPress ), I think I got it :)

In the function bt_generate_attachment_metadata, I've just modified the call to bt_image_make_intermediate_size including the last parameter $size

$resized = bt_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );

And modified the beggining of the function bt_image_make_intermediate_size as follows:

  • added the $size parameter to the function
  • instead of the default null value to $suffix, a switch to our new suffixes
function bt_image_make_intermediate_size( $file, $width, $height, $crop = false, $size ) {
    if ( $width || $height ) {
        switch($size) {
            case 'thumbnail':
                $suffix = 't';
                break;
            case 'medium':
                $suffix = 'm';
                break;
            case 'large':
                $suffix = 'l';
                break;
            default:
                $suffix = null;
                break;
        }
        $resized_file = bt_image_resize( $file, $width, $height, $crop, $suffix, null, 90 );

Here, a copy of the full code with my mods, just for reference.
And the diff from the original.

Much probably, all the code can be shrank to a bare bone, but this way we get the benefit of custom cropped images :))

Seems that the answer is no...

I've followed the core functions and found a dead-end. And found this post ( How can I make add_image_size() crop from the top? ) where Rarst says:

Intermediate image generation is extremely rigid. Image_resize() keeps it close to code and completely lacks hooks.

But, following the lead of the other answer (from bradt) and the code he published ( Image Crop Position in WordPress ), I think I got it :)

In the function bt_generate_attachment_metadata, I've just modified the call to bt_image_make_intermediate_size including the last parameter $size

$resized = bt_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );

And modified the beggining of the function bt_image_make_intermediate_size as follows:

  • added the $size parameter to the function
  • instead of the default null value to $suffix, a switch to our new suffixes
function bt_image_make_intermediate_size( $file, $width, $height, $crop = false, $size ) {
    if ( $width || $height ) {
        switch($size) {
            case 'thumbnail':
                $suffix = 't';
                break;
            case 'medium':
                $suffix = 'm';
                break;
            case 'large':
                $suffix = 'l';
                break;
            default:
                $suffix = null;
                break;
        }
        $resized_file = bt_image_resize( $file, $width, $height, $crop, $suffix, null, 90 );

Here, a copy of the full code with my mods, just for reference.
And the diff from the original.

Much probably, all the code can be shrank to a bare bone, but this way we get the benefit of custom cropped images :))

Seems that the answer is no...

I've followed the core functions and found a dead-end. And found this post ( How can I make add_image_size() crop from the top? ) where Rarst says:

Intermediate image generation is extremely rigid. Image_resize() keeps it close to code and completely lacks hooks.

But, following the lead of the other answer (from bradt) and the code he published ( Image Crop Position in WordPress ), I think I got it :)

In the function bt_generate_attachment_metadata, I've just modified the call to bt_image_make_intermediate_size including the last parameter $size

$resized = bt_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );

And modified the beggining of the function bt_image_make_intermediate_size as follows:

  • added the $size parameter to the function
  • instead of the default null value to $suffix, a switch to our new suffixes
function bt_image_make_intermediate_size( $file, $width, $height, $crop = false, $size ) {
    if ( $width || $height ) {
        switch($size) {
            case 'thumbnail':
                $suffix = 't';
                break;
            case 'medium':
                $suffix = 'm';
                break;
            case 'large':
                $suffix = 'l';
                break;
            default:
                $suffix = null;
                break;
        }
        $resized_file = bt_image_resize( $file, $width, $height, $crop, $suffix, null, 90 );

Here, a copy of the full code with my mods, just for reference.
And the diff from the original.

Much probably, all the code can be shrank to a bare bone, but this way we get the benefit of custom cropped images :))

Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264

Seems that the answer is no...

I've followed the core functions and found a dead-end. And found this post ( How can I make add_image_size() crop from the top? ) where Rarst says:

Intermediate image generation is extremely rigid. Image_resize() keeps it close to code and completely lacks hooks.

But, following the lead of the other answer (from bradt) and the code he published ( Image Crop Position in WordPress ), I think I got it :)

In the function bt_generate_attachment_metadata, I've just modified the call to bt_image_make_intermediate_size including the last parameter $size

$resized = bt_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'], $size );

And modified the beggining of the function bt_image_make_intermediate_size as follows:

  • added the $size parameter to the function
  • instead of the default null value to $suffix, a switch to our new suffixes
function bt_image_make_intermediate_size( $file, $width, $height, $crop = false, $size ) {
    if ( $width || $height ) {
        switch($size) {
            case 'thumbnail':
                $suffix = 't';
                break;
            case 'medium':
                $suffix = 'm';
                break;
            case 'large':
                $suffix = 'l';
                break;
            default:
                $suffix = null;
                break;
        }
        $resized_file = bt_image_resize( $file, $width, $height, $crop, $suffix, null, 90 );

Here, a copy of the full code with my mods, just for reference.
And the diff from the original.

Much probably, all the code can be shrank to a bare bone, but this way we get the benefit of custom cropped images :))