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

External image files not processed #1

Open
withindale opened this issue Sep 21, 2019 · 4 comments
Open

External image files not processed #1

withindale opened this issue Sep 21, 2019 · 4 comments
Labels
question Further information is requested

Comments

@withindale
Copy link

withindale commented Sep 21, 2019

Thank you for the Aura plug-in.

Our GRAV website is at url/en but some images are in url/images and Aura does not output them.

This appends a quick fix:

if ($filename) {
        $imagePath = $page->path() . '/' . $filename;
        if (file_exists($imagePath)) {
            $size = getimagesize($imagePath);
            $this->webpage->image = new Image();
            $this->webpage->image->url = $page->url(true) . '/' . $filename;
            $this->webpage->image->id = $this->webpage->url . '#primaryimage';
            $this->webpage->image->width = $size[0];
            $this->webpage->image->height = $size[1];
            $this->webpage->image->caption = $this->webpage->title;
            $this->webpage->image->type = $size['mime'];
        }
        else {
            $this->webpage->image = new Image();
            $this->webpage->image->url = $filename;
            $size = getimagesize($filename);
            $this->webpage->image->width = $size[0];
            $this->webpage->image->height = $size[1];
            $this->webpage->image->type = $size['mime'];
        }
    }
@matt-j-m
Copy link
Owner

matt-j-m commented Feb 9, 2020

Hi @withindale are you using the filepicker (in the Grav Admin panel) to select your image? That is the way the plugin is intended to work, which I believe means you would need to store the image within the same directory as your *.md file. Please let me know if that is not the case or if I'm misunderstanding the issue. Thanks.

@matt-j-m matt-j-m added the question Further information is requested label Feb 9, 2020
@withindale
Copy link
Author

withindale commented Feb 12, 2020 via email

@matt-j-m
Copy link
Owner

Hi again Ian

Going by your example fix I'm guessing you are providing the full URL to the image, is that correct? Enabling this would allow users to input URLs outside of their Grav installation, which is not necessarily bad, but it does increase the risk that the image may be changed, moved etc. without the user's knowledge. getimagesize will return unexpected results unless the image can first be verified to exist, and the file_exists function doesn't work well with URLs, apparently.

Having said that, if you are linking to images within a user defined media directory within the same website, you could provide a relative path to the file (e.g. '/images/file.png'), then the file_exists and getimagesize functions would be safe to use. Updated code would be something like:

if ($filename) {
    $imagePath = false;
    // Test existence of image at page level 
    $imagePathPageLevel = $page->path() . '/' . $filename;
    if (file_exists($imagePathPageLevel)) {
        $imagePath = $imagePathPageLevel;
        $imageUrl = $page->url(true) . '/' . $filename;
    } else {
        // Test existence of image at root level
        $imagePathSiteLevel = ROOT_DIR . $filename;
        if (file_exists($imagePathSiteLevel)) {
            $imagePath = $imagePathSiteLevel;
            $imageUrl = $this->grav['base_url_absolute'] . $filename;
        }
    }
    if ($imagePath) {
        $size = getimagesize($imagePath);
        $this->webpage->image = new Image();
        $this->webpage->image->url = $imageUrl;
        $this->webpage->image->id = $this->webpage->url . '#primaryimage';
        $this->webpage->image->width = $size[0];
        $this->webpage->image->height = $size[1];
        $this->webpage->image->caption = $this->webpage->title;
        $this->webpage->image->type = $size['mime'];
    }
}

Would that work for you?

@withindale
Copy link
Author

withindale commented Mar 3, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants