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

Image TransformSourcePath #3

Closed
tim-thaler opened this issue Nov 16, 2020 · 2 comments
Closed

Image TransformSourcePath #3

tim-thaler opened this issue Nov 16, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tim-thaler
Copy link

Hello Kyle,
thank you for your work on this plugin!

I only use the local file storage and I found that if I use "@webroot/files" in the public URL field, I get an error because the file can't be retrieved.

Transform.php (Row 168)
$masterImage = $asset->url;

needs to be changed to, but I'm not sure

$masterImage = $asset->getImageTransformSourcePath();

@codewithkyle codewithkyle self-assigned this Nov 16, 2020
@codewithkyle codewithkyle added the bug Something isn't working label Nov 16, 2020
@codewithkyle
Copy link
Owner

codewithkyle commented Nov 16, 2020

Can you provide a bit more information such as your Craft CMS version, PHP version, and what Image Driver you're using. You can get this info from Utilities -> System Report -> Application Info.

I'm not able to recreate the issue on Craft 3.5.14 with PHP 7.2.1. Using getImageTransformSourcePath() seems like a better option than the current implementation but I want to make sure it will fix your issue before I release the fix and close this issue.

When I set my Base URL field to @webroot/images I'm not recieving any errors before or after changing to the getImageTransformSourcePath() method.

{% set transformedImageUrl = "/jitter/v1/transform&id=" ~ entry.image[0].id ~ "&w=150&ar=1:1&m=fit&fm=gif&q=10" %}
<img 
    src="{{ transformedImageUrl }}" 
    srcset="{{ craft.jitter.srcset(entry.image[0], [
        { w: 300, h: 250, },
        { w: 768, ar: "16:9", },
        { w: 1024, ar: "16:9", q: 100 },
    ]) }}" 
    loading="lazy"
    width="1024"
/>

@tim-thaler
Copy link
Author

tim-thaler commented Nov 19, 2020

Hi Kyle, I had further investigations.

First thing was more a problem of my server configuration. If you run the system behind a .htaccess protected area, you need to make sure that the server itself can call the image source without getting 401 - permission denied ;-)

Second thing what I found is that if you have a DOCUMENT_ROOT with "." your regex for the contenttype doesn't work properly.
Example: /var/www/example.com/public/images/image.jpg

Instead of:

preg_match("/(\..*)$/", $existingFile, $matches);
$contentType = ltrim($matches[0], ".");

Needs to be:

preg_match("/(\..{1,4})$/", $existingFile, $matches);
$contentType = ltrim($matches[0], ".");

Now it works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants