Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retina? #2

Open
Bluxart opened this issue Jan 10, 2024 · 2 comments
Open

Retina? #2

Bluxart opened this issue Jan 10, 2024 · 2 comments

Comments

@Bluxart
Copy link

Bluxart commented Jan 10, 2024

Hi, nice script but I don't understand how to work the retina feature.

I upload an image 870x706

I call your function in this way
$img_lg = nova_resize_thumbnail($img_id, array( 'width' => '435', 'height' => '353', ), true );

The output is this and the retina value is empty
Array ( [url] => https://growme.it/fing/wp-content/uploads/2024/01/[email protected] [width] => 435 [height] => 353 [retina] => )

Any tips?

@wpexplorer
Copy link
Owner

@Bluxart - That is correct. When you set retina to true it returns the retina URL. So if you are showing an image for example that has both retina and non retina you would call the function twice:

$img_lg = nova_resize_thumbnail($img_id, array( 'width'  => '435', 'height' => '353', ) );
$img_lg_retina = nova_resize_thumbnail($img_id, array( 'width'  => '435', 'height' => '353', ), true );

if ( ! empty( $img_lg['url'] ) ) {
    $image = '<img src="' . esc_url( $img_lg['url'] ) . '" height="' . esc_attr( $img_lg['height'] ) . '" width="' . esc_attr( $img_lg['width'] ) . '" srcset="' . esc_url( $img_lg['url'] ) . ' 1x,' . esc_url( $img_lg_retina['url'] ) . ' 2x">';
}

I made this script over 7 years ago though. So honestly it may need some updating...

  • AJ

@wpexplorer
Copy link
Owner

Forgot to mention....At the top of the script you see the variable:

$retina_support = false;

If you set this to true then you would call an image like this:

$img_lg = nova_resize_thumbnail($img_id, array( 'width' => '435', 'height' => '353', ) );

And it will generate retina versions automatically, that's when you will get a value in the retina parameter of the result array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants