Skip to main content

Eager transformation based on condition for one image size

Comments

3 comments

  • Stephen Doyle

    Hi Kumar,

    May I please ask you for some more information about what you're trying to do?

    I wasn't sure if you want to add a new eager transformation, but decide in your application code whether or not to use it, or you want to use a conditional transformation where the output of the transformation is different based on some conditions that are part of the transformation itself - could you please let me know? I'd be happy to provide an example of either

    -Stephen

     

    0
  • Kumar

    Hi Stephen,

     

    Thanks for your reply. When the user uploads an image am generating different sizes of images (thumbnail, small image, medium image, large image) and wants to add other size extra large image based on condition if width > 1920 px. For that how i need to change the above code?

    0
  • Stephen Doyle

    Hi Kumar,

    You won't know the image dimensions in the code example you've provided unless you do some client-side analysis of the file.

    If you want to request an eager transformation only for files which are larger than 1920px as part of the upload itself, you'll need to handle that in your own code by examining the original file and choosing whether to add another transformation to the list of requested eager transformations.

    As an alternative where you don't need to do that, you could do one of the following:

    * Request an eager transformation using a crop mode which won't upscale a smaller image, such as `limit`. When you get the upload response and know the size of the original, you can save that information and choose not to use the 'extra large' version in your app's code for images which are smaller than 1920 pixels wide

    * Wait until the upload API call returns and you know the dimensions, and if the image was wider than 1920 pixels, make another API call using the explicit() API method to request the larger eager transformation is created

    * As above, but use an on-the-fly transformation for the 1920 wide version

    Please take a look and see if that helps,

    Stephen

     

    0

Post is closed for comments.