Следующий код работает. Важная новая часть, которая заставила скрипт работать:
foreach ($imagesTypes as $imageType) {
\ImageManager::resize($tmpfile, $new_path . '-' . stripslashes($imageType['name']) . '.' . 'jpg', $imageType['width'], $imageType['height'], 'jpg');
if ($generate_hight_dpi_images) {
\ImageManager::resize($tmpfile, $new_path . '-' . stripslashes($imageType['name']) . '2x.' . 'jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2, 'jpg');
}
}
Полный код:
if(array_key_exists('images', $ps16ProductObject['product']['associations'])) {
foreach($ps16ProductObject['product']['associations']['images'] as $imagePs16Id) {
$image = new \Image();
$image->id_product = (int) $ps16ProductObject['product']['id'];
$image->position = \Image::getHighestPosition($ps16ProductObject['product']['id']) + 1;
if (!\Image::getCover($image->id_product)) {
$image->cover = 1;
} else {
$image->cover = 0;
}
$image->add();
$new_path = $image->getPathForCreation();
$tmpfile = dirname( __FILE__ ) . '/../temp.jpg';
$ps16image = $this->ps16Client->get([
'resource' => 'images/products/' . $ps16ProductObject['product']['id'] . '/' . $imagePs16Id['id']
]);
file_put_contents($tmpfile, $ps16image);
\ImageManager::resize($tmpfile, $new_path . '.' . 'jpg', null, null, 'jpg', false);
$imagesTypes = \ImageType::getImagesTypes('products');
$generate_hight_dpi_images = (bool) \Configuration::get('PS_HIGHT_DPI');
foreach ($imagesTypes as $imageType) {
\ImageManager::resize($tmpfile, $new_path . '-' . stripslashes($imageType['name']) . '.' . 'jpg', $imageType['width'], $imageType['height'], 'jpg');
if ($generate_hight_dpi_images) {
\ImageManager::resize($tmpfile, $new_path . '-' . stripslashes($imageType['name']) . '2x.' . 'jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2, 'jpg');
}
}
unlink($tmpfile);
}
}