junaidbhura / fly-dynamic-image-resizer

Fly Dynamic Image Resizer plugin for WordPress
https://wordpress.org/plugins/fly-dynamic-image-resizer/
MIT License
162 stars 26 forks source link

Some images are not displayed #28

Closed jaroSK closed 5 years ago

jaroSK commented 5 years ago

I'm using this code to display photos of contact persons:

<?php if( has_post_thumbnail( $data['contact_person']->ID ) ): ?>
    <div>
        <?php
            $retina = fly_get_attachment_image_src( get_post_thumbnail_id( $data['contact_person']->ID ), array( 160, 160 ), 1 );
            echo fly_get_attachment_image( get_post_thumbnail_id( $data['contact_person']->ID ), array( 80, 80 ), 1, array( 'class' => 'mwn mr-4', 'srcset' => $retina['src'] . " 2x" ) );
        ?>
    </div>
<?php endif ?>

Most of the images are displayed correctly, as you can see here, but on some pages there is an error - Notice: Undefined index: src on line 315 as you can see here. How to edit code to work for all images?

horecny commented 5 years ago

Ahoj Jaro, skus to zdebugovat viac do hlbky, my s tym nemame problemy, mame nad tym spravene vlastne classy ale pouzivame to nejak takto:

if ( function_exists( 'fly_get_attachment_image_src' ) && $size !== 'post-thumbnail' && ! empty( fly_get_image_size( $size ) ) ) { if ( $image_data = fly_get_attachment_image_src( $id, $size, $crop ) ) { $image = isset( $image_data['src'] ) ? $image_data['src'] : $image_data[0]; } } $image nasledne je url obrazku

Hi Jaro, try to check in more depth your debug of variables and function outputs, anyway check my code below, which we are using as part of wrapper of fly images plugin

junaidbhura commented 5 years ago

Hey @jaroSK and @horecny sounds like the problem exists outside the plugin, so I'm closing this issue!

jaroSK commented 5 years ago

It looks like that some images are not created in fly-images directory. Then this if statement in class-core.php doesn't return array with image src.

// Check if file exsists
if ( file_exists( $fly_file_path ) ) {
    $image_size = getimagesize( $fly_file_path );
    if ( ! empty( $image_size ) ) {
        return array(
            'src'    => $this->get_fly_path( $fly_file_path ),
            'width'  => $image_size[0],
            'height' => $image_size[1],
        );
    } else {
        return array();
    }
}

Are there any restrictions on image size, image extensions or characters in image name?