Jump to content

Generate image via api


nabo
 Share

Recommended Posts

Hello

is there a way to generate a different size image via api during the same process of import?

product->setOutputFormatting(false);
$product->images->add($file_url);
$product->save();

 

Link to comment
Share on other sites

The way I would deal with the question is looking at InputfieldImage's code. It has an option to resize image if it is larger than defined maximum width and hight. I think it is around here.

The logic seems to be:

  • loading the original sized image first,
  • making a resized copy,
  • then deleting original image
  • and saving resized image with original image filename.
Link to comment
Share on other sites

@nabo, I think you can just do some Pageimage resizing method on the last item in the field, which will be the image you just added.

$product->setOutputFormatting(false);
$product->images->add($file_url);
$product->save();
// create variation of image
$product->images->last->size(400, 300); // whatever resizing method you want

 

  • Like 1
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...