question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No apparent clean way to access the image object corresponding to a field

See original GitHub issue

I posted this on the Lektor Gitter channel, and one of the devs who’s worked on the image processing infrastructure, @xlotlu , instructed me to post this here as a bug.

I’m putting the finishing touches on a thoroughly overhauled version of Lektor-Icon, a modern, highly responsive single-page theme (of that sort that it seems all the flashy personal and business “showcase”-type sites are after these days…) that also includes a blog and other goodies. I’m wanting to implement responsive image sizing, i.e. to be able to feed lektor one high resolution source image and spit out differently-sized versions with thumbnail() for use with srcset, or even just resizing one image appropriately.

However, I’m pretty new to all this, so and I can’t find a particularly clean and robust way to just turn the image name/path from a field into an image object that works with thumbnail. It seems there should be some way either in the model setup or a function to get the image at a filename/path, but I can’t seem to find it. The best I was able to do is call {% set hero_img_file = record.attachments.get(this.image) %} inside the HTML template for the flowblock, and then call .thumbnail(). Here’s a minimal example of such a flowblock model:

[block]
name = Hero

[fields.image]
label = Hero Background Image
type = select
source = record.attachments.images

and in my contents.lr I have

hero:

#### hero ####
image: camg-classic-storm-rainbow.jpg
---

But that seems quite clunky and overly complex; I figure there must be a better way I’m missing, but it seems @xlotlu didn’t know of one either. Incidentally when trying to get the parent (to work around this and call this.parent.attachments, before I stumbled across record.attachments), I also found this.parent doesn’t work for a flowblock; can that possibly be intended? Is there any other way to get a flowblock’s parent object if its needed?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
nixjdmcommented, Dec 6, 2018

I thought it [flowblocks] was intended to accommodate more than one type of block

You’re right. I was being reductionist, sorry. I was trying to emphasize the “arbitrary number” bit. Thank you for the background on what you’re going through.

There’s a lot I could address here, but I’ll try to stay on topic.

@CAM-Gerlach come to think of it, there could easily be be an Image() template function, and that might prove useful in other scenarios too (e.g. deriving dimensions or getting thumbnails of images from assets). @nixjdm what say you?

I.e. a function Image() that takes a string of the path and gets the appropriate image object, allowing the thumbnail(), etc. methods and attributes to be called on it.

This is related to #484. One way or the other, assets, and in particular image assets, should be made easier to work with. That you can’t call .thumbnail on an asset is problem. Soon, videos could have the same problem. Every method of Attachment instances and subclass (Images, Videos, future types) instances that makes sense for assets should still be something you can get, but for a lot of them you can’t.

1reaction
xlotlucommented, Dec 6, 2018

just getting the image object directly from a path, or even including an image field type that automatically treats its value as a path to an image

@CAM-Gerlach the first half of this is captured in #625, the other half being the actual “image”-type field. I suggest you create a new issue for it to can keep things orderly, since this kinda turned into a support / philosophical discussion.

(As well for any other issues you captured here. E.g. appending to a template block from another, to be able to push styles into <head>? Anything else?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image Processing with Python - Data Carpentry
When we process images, we can access, examine, and / or change the colour of any pixel we wish. To do this, we...
Read more >
Basic Image Processing with FIJI/ImageJ
1.1 IMPORTANT CONSIDERATIONS. • Images are data. NEVER overwrite an original image file. If you make adjustments to the image, save it as...
Read more >
Manage access to custom images - Compute Engine
This document describes the required IAM permissions for creating and managing custom images and how to give them to users.
Read more >
Attach files and graphics to the records in your database
By using attachments, you open documents and other non-image files in their parent programs, so from within Access, you can search and edit...
Read more >
Introduction to MATLAB with Image Processing Toolbox - Video
An image processing example is used to show you how to get started using MATLAB. Highlights include: Interactively importing and visualizing image data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found