File created within a hook not appearing on the panel

Hi everyone I used imagick to create an jpeg from a pdf page within a file.create:after panel hook. The jpeg is being created fine but is not appearing in the panel file section because the .txt file corresponding to the image is not created. Is there some method to create this file as well?

Thanks in advance.

Have you limited your file section by setting the template option?

Could you post your code so that we can see how you create the file?

oh right! I was usign de starterkit that has the files section filtered by template. Thanks @texnixe!
Now the file appears, but another related quiestion. When I upload an image in kirby panel it creates an empty .txt with the same image name. Is this really needed?

Btw this is my code for extract as jpeg the first page of the pdf.

//config.php
'hooks' => [
  'file.create:after' => function ($file) {
    try {
      if ($file->extension() == 'pdf' ) {
        $output_format = "jpeg"; 
        $preview_page = "1"; 
        $resolution = "300"; 
        $output_file = $file->page()->root()."/".$file->name().".jpg"; 
      
        $img_data = new Imagick(); 
        $img_data->setResolution( $resolution, $resolution ); 
        $img_data->readImage( $file->root() . "[" . ($preview_page - 1) . "]" ); 
        $img_data->setImageFormat( $output_format ); 
      
        file_put_contents( $output_file, $img_data, FILE_USE_INCLUDE_PATH ); 
      }
    } catch (Exception $e) {
        throw new Exception($e->getMessage());
    }
  }
]
2 Likes

I don’t know if it is possible to prevent that. The file is needed for example if you sort images manually, as the sort number is stored in the meta data file (as well as any other information you want to store there).

1 Like

ok perfect, thanks!