Thumbs link to file

Hello,

try to use the thumb() function with a simple slider,
but how get the link to the created thumb file?

this line: thumb($file, array(‘width’ => 300))

produced only the link to the original image

        <?php
     

          //  SLIDER
          // Transform the comma-separated list of filenames into a file collection
          $filenames = $article->attachments()->split(',');
         
          
          if(count($filenames) > 2)
            {
                

              $filenames = array_pad($filenames, 2, '');

            
              echo '<div class="slider">';
              echo ' <div class="slider_nav">';
              echo ' <a class="back" href=""></a>';
              echo ' <a class="next" href=""></a>' ;
              echo '</div>';
              echo '<ul>';
              $files = call_user_func_array(array($article->files(), 'find'), $filenames);
              
              // Use the file collection
              foreach($files as $file)
                {
                    //echo $file->url();
                  echo "<li>".thumb($file, array('width' => 300))."</li>";
                }

              echo '</ul>';
              echo '</div>';
            }

              
              
            //IMAGE WITHOUT SLIDER
          else
            {
              $filenames = array_pad($filenames, 2, '');

            
              
              $files = call_user_func_array(array($article->files(), 'find'), $filenames);
              
              // Use the file collection
              foreach($files as $file)
              {
                //echo $file->url();
                echo "<li>".thumb($file, array('width' => 300))."</li>";
              }
              echo '<figcaption>'.$article->caption()->kirbytext().'</figcaption>';


                 
                
            }
                   


        ?>

greetings perry

Do you mean the URL of the generated thumb? If so, use the url method:

thumb($file, array('width' => 300))->url()

No, also produces a link to the original file

echo "<li><img src=".thumb($file, array('width' => 300))->url()."></li>";

Does your thumb directory exist and is it writable for your web server? This is often the reason for this issue.

@lukasbestle is right, recently I was having the same issue on a production server where Memcache (the cache driver I used) didn’t have permission to write to the thumb directory. Fixing the permission solved the issue.

@all:
yes thank you now it works. It was the file permissions.

retina displays
it have an option not to reduce the image resolution(dpi) ?

There is no such thing as DPI when displaying an image on a screen. A retina image is simply an image with twice the width and height (and therefore four times the amount of pixels).

Retina&img’s

Thank you lukasbestle,
I was on the wrong way.