bymayo / craft-pdf-transform

Transform a PDF page to an image (JPEG, PNG)
MIT License
12 stars 9 forks source link

If Volume includes Subpath, new asset is generated every time #25

Open rogerdawkins opened 3 months ago

rogerdawkins commented 3 months ago

I have the following simple setup: Filesystem: Images (local folder) Base URL: @web/assets/img

Asset Volume: Thumbnails which uses the above FS Subpath: thumbnails

If the Subpath is not set then PDF Transform works fine, but with the Subpath set then PDF Transform generates a new Asset always, i.e. it doesn't use the previously generated image.

The reason appears to be in the render function (PdfTransformService.php) as below:

$volume = $this->getImageVolume();
$fs = $this->getImageFs();
$fileName = $this->getFileName($asset);

if ($fs->fileExists($fileName)) {

  $transformedAsset = Asset::find()
    ->volumeId($volume->id)
    ->filename($fileName)
    ->one();

  return $transformedAsset;
}

The issue is that the fileExists is being checked against the filesystem which is only the basepath and doesn't include the subpath. If the $fs->fileExists is changed to $volume->fileExists then the full path is used and the generated image is returned rather than a new asset.

Do you want me to create a PR?