Accept Image based on resolution in image component | Community
Skip to main content
June 21, 2023
Solved

Accept Image based on resolution in image component

  • June 21, 2023
  • 1 reply
  • 700 views

Hi, 
In the image component when we select a image in dialog box, Is it possible to accept image only if its is having a specific resolution Ex:(1800 x 1200, 2272 x 1704, 3072 x 2304 ) or can we set any minimum resolution for image in image component, so that any image selected below minimum resolution should not be allowed.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by MayurSatav

Hi @m1064615 ,

There is no OOTB feature to restrict the image selection based on specific resolutions for the image component. However, you can achieve this functionality by implementing a custom validation logic in /libs/core/wcm/components/image/v2/image/clientlibs/editor/js/image.js the core image component's dialog core/wcm/components/image/v2/image.

 

$imageField.on("change", function () { var file = this.files[0]; var image = new Image(); image.onload = function () { var width = this.width; var height = this.height; if (width < MIN_WIDTH || height < MIN_HEIGHT) { // Display an error message to the author alert("Please select an image with a minimum resolution of " + MIN_WIDTH + "x" + MIN_HEIGHT + " pixels."); // Reset the selected image field $imageField.val(""); } };

1 reply

MayurSatav
Community Advisor and Adobe Champion
MayurSatavCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
June 21, 2023

Hi @m1064615 ,

There is no OOTB feature to restrict the image selection based on specific resolutions for the image component. However, you can achieve this functionality by implementing a custom validation logic in /libs/core/wcm/components/image/v2/image/clientlibs/editor/js/image.js the core image component's dialog core/wcm/components/image/v2/image.

 

$imageField.on("change", function () { var file = this.files[0]; var image = new Image(); image.onload = function () { var width = this.width; var height = this.height; if (width < MIN_WIDTH || height < MIN_HEIGHT) { // Display an error message to the author alert("Please select an image with a minimum resolution of " + MIN_WIDTH + "x" + MIN_HEIGHT + " pixels."); // Reset the selected image field $imageField.val(""); } };
M1064615Author
June 22, 2023

Hi MayurSatav,
Need clarification on below points.

  1. Path is /libs/core/wcm/components/image/v2/image/clientlibs/editor/js/image.js or it is /apps/core/wcm/components/image/v2/image/clientlibs/editor/js/image.js
  2. $imageField is to be declared?
  3. what value need to be assigned for $imageField ?
  4. Var file is declared but not utilised further.