3

I’m trying to display products in my store through a third party application using Magento’s web services API. When I query image data for an item using “catalog_product_attribute_media.list”, I get something like this:

Array
(
    [0] => Array
        (
            [file] => /a/k/akio-dresser.jpg
            [label] => 
            [position] => 1
            [exclude] => 1
            [url] => http://example.com/magento/media/catalog/product/a/k/akio-dresser.jpg
            [types] => Array
                (
                    [0] => thumbnail
                    [1] => small_image
                    [2] => image
                )

        )

)

This tells me that I should be able to get the “thumbnail” or “small_image” version of this image, but I can’t figure out how to actually do it. I’ve looked through the documentation and tried everything I could find but have had no success. Does anybody else know what SOAP call I could use? The call catalog_product_attribute_media.info seems to return exactly the same information, and catalog_product_attribute_media.types doesn’t seem to return anything at all.

Syed Absar
  • 2,274
  • 1
  • 26
  • 45

1 Answers1

2

The API call result refers to the original file(s) for the product image(s), not the cached thumbnails/small images that are generated at runtime, i.e. when the product page is loaded.

The returned attributes correspond to the layout that you get in the admin page for the product. So a given image can be used for the main product image on the product page, the small image used in the category listings or the thumbnail used for when added to basket.

Magento scales these images on the fly, this is a much better arrangement that what you get with some older carts where you have to get images prepared to 'correct' sizes. However, that means that there is nothing but a cached copy of the thumbnail on disk with no API call to access it.

I faced a similar problem of wanting the product images outside of Magento. My workaround was to use a cron script to pull down the big original images that had changed in the last 24 hours, to then create the thumbnails with imagemagick and then use the new 'local' copy of the image.
This was no workaround, I actually wanted to do some command line processing to the thumbnails, to remove excess whitespace, sharpen the edges and add some extra vibrancy to the colours. This image processing was not realistic in real time and I did not want the default 'blurry' thumbnails anyway. An overnight cron-job on just the fresh images did the job for me.

ʍǝɥʇɐɯ
  • 4,012
  • 7
  • 32
  • 53
  • There is an option to upload 3 different sizes of product images in Magento, no? – Syed Absar Jun 17 '11 at 06:10
  • Have as many as you like then see the API call results - it shows what image is used for what. – ʍǝɥʇɐɯ Jun 17 '11 at 10:59
  • and we have no access to those images in the service? wow! :( – Syed Absar Jun 17 '11 at 12:49
  • You get the URL for the image, you can then do what you want with it. That is far preferable to the image being encoded as a mime type and sent through the API. You can also put the images on a separate CDN and have Magento get images from system-B if need be. – ʍǝɥʇɐɯ Jun 17 '11 at 14:56
  • The SOAP call sends back multiple images. Is there anyway to know which one is being used for the thumbnail image? – Larry Hipp Jul 07 '11 at 13:46
  • 1
    @hipplar If it is in the 'types' array as 'image' then that is the main product image, 'thumbnail' means it is used for thumbnail. you must iterate over array to find it though. – ʍǝɥʇɐɯ Jul 07 '11 at 13:51
  • @ʍǝɥʇɐɯ The interesting thing is I get a list back with 3 catalogProductImageEntities but only the first item in the list has the "types" array populated. The types array has 3 items in it as well (thumbnail, small image, image). Does this mean that this image would be used in all three image "types"? – Larry Hipp Jul 07 '11 at 13:57