Jump to content

Image resizing without using images field


MSP01
 Share

Recommended Posts

Hi,

We have a webstore made with PW, where product images are saved in a custom folder directly from ERP. The image url's would be saved in simple text fields. Is it possible to use PW's image resizing functionality when someone visits the page, without actually saving the images into the images field?

Link to comment
Share on other sites

Same folder with originals with a prefix/affix or possibly a subfolder. It doesn't really matter to us.  The image paths in frontend could be hardcoded to fetch the thumbnails, so PW's image-size()->url wouldn't be needed for that.

All we're trying to avoid is making one giant job of creating all different image sizes in one go.

Link to comment
Share on other sites

Just resize via an API call within the <img> tag, eg:

<img src="<?=$page->image->size(400, 0)->url?>" />

That will resize, store it (not visible in the admin) and display it on the frontend where called and will be available to all future calls without going through the actual resize each time.

Link to comment
Share on other sites

4 hours ago, MSP01 said:

Same folder with originals with a prefix/affix or possibly a subfolder. It doesn't really matter to us.  The image paths in frontend could be hardcoded to fetch the thumbnails, so PW's image-size()->url wouldn't be needed for that.

All we're trying to avoid is making one giant job of creating all different image sizes in one go.

Not sure if I got this right, but when you say that the images are "in a custom folder directly from ERP", do you mean that this custom folder is at the local disk, not some external server/service/whatever? If that's the case, you can resize them with ImageSizer, but it requires going through some extra hoops. You may find this thread useful — it's about generating resized versions of Pagefiles, but the concept here is similar, with the difference that the path to file is not in a Pagefile object but rather your text field.

That being said, it would be much easier if you would just store those images in an image field on one of your pages. The process would be more straightforward, you wouldn't need to worry about cleaning up old variations, and so on.

I guess the TL;DR here is that if you have a good reason for not handling those images as regular ProcessWire images, then yes, technically it's possible to do what you've asked here with ImageSizer, but a) this is rarely the best approach, and b) even then you may find working with Imagick or something similar directly a tad easier ?

  • Like 3
Link to comment
Share on other sites

Following on from what @teppo suggests, note that it's quite straightforward to write a script to import images into image fields on pages. There's lots of help on the forums for doing this (as a starting point, https://www.google.com/search?as_q=import+images&as_sitesearch=processwire.com).

So, if you have a way of getting the image URLs into text fields (which it seems you have), you could write a script to run over the pages, loading the image(s) from the URL(s).

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...