Jump to content

Resizing images outside PW folders


Roope
 Share

Recommended Posts

I'm building a product site where single product page wouldn't have any image field on it but instead we would use product images from another folder outside PW folders. All images are named using product SKU number that we store to text field during product import.

Reason for this is that we already have images in place and we dont need (nor want) for images to be visible or uploadable through PW admin. Customer is used to mass update images via FTP and we don't want to break that.

So question is, can we still use API to resize images or is it impossible outside wire array and filesystem?

Link to comment
Share on other sites

Thanks for your reply sakkoulas!

No, this isn't quite what im looking for since I wouldn't have any image field attached to product template.

Situation is more like this:

// set root for product images
$root = $config->urls->root . 'images/';

// set product image filename using product sku number
$name = $sanitizer->pageName($page->sku) . '_01.jpg';

// get product main image
$image = file_exists($root.$name) ? $root.$name : null;

// now, resize image using PW API
if ($image) $image = $image->size(300,200);
Link to comment
Share on other sites

Yep, this looks right - thanks Soma!

And ImageSizer seems to create new image to the same path as original so I think this should work just fine.

I'll test it and report findings here!

Link to comment
Share on other sites

OK, so this behaves as excepted. Defined image gets resized.

But it overwrites the original file so this is not perfect solution for my need. Is there a way to make it create size variation from original without overwriting? I didn't find any options for this in ImageSizer class so how is it done in API? Should I just first copy and rename original image and resize that one?

Link to comment
Share on other sites

Should I just first copy and rename original image and resize that one?

Yes, this is basically what Pageimage does internally. You can use PHP's copy() command. 

  • Like 2
Link to comment
Share on other sites

  • 2 years later...

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...