How could i limit store vendor only upload 600 x 600 px image at product?

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WCFM How could i limit store vendor only upload 600 x 600 px image at product?

Viewing 18 reply threads
  • Author
    Posts
    • #40191
      MOHO
      Participant

      I find out the square image will be good look

      Or could i limit store vendor only upload square image?

      Attachments:
      You must be logged in to view attached files.
    • #40473
      WCFM Forum
      Keymaster

      HI,

      You should more concern about actual product page image display.

      How that looks?

      Thank You

    • #40474
      MOHO
      Participant

      If the user upload not square image, it will not good look at frontend.

    • #40485
      WCFM Forum
      Keymaster

      Umm .. normally themes comes with function to adjust images as per product template.

      Is this not happening in your site?

      Can you please ask theme author once regarding this?

      Thank You

    • #40501
      WCFM Forum
      Keymaster

      Hi,

      You may use this code for the purpose ->

      function wcfm_max_image_size( $file ) {
       
        $img     = getimagesize($file['tmp_name']);
      	$minimum = array('width' => '600', 'height' => '600');
      	$width   = $img[0];
      	$height  = $img[1];
      
      	if ($width > $minimum['width'] )
      		return array("error"=>"Image dimensions are too large. Maximum width is {$minimum['width']}px. Uploaded image width is $width px");
      	elseif ($width < $minimum['width'] )
      		return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px");
      	elseif ($height >  $minimum['height'])
      		return array("error"=>"Image dimensions are too large. Maximum height is {$minimum['height']}px. Uploaded image height is $height px");
      	elseif ($height <  $minimum['height'])
      		return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
      	else
      		return $file; 
        
        return $file;
      }
      add_filter( 'wp_handle_upload_prefilter', 'wcfm_max_image_size' );

      Thank You

    • #40824
      MOHO
      Participant

      great i see

      Image dimensions are too large. Maximum width is 600px. Uploaded image width is 1200 px

      Image dimensions are too small. Minimum width is 600px. Uploaded image width is 300 px

      ————-
      Minimum width 600px
      Maximum width 1200px

      could you yell me how to change it, thanks

    • #40883
      WCFM Forum
      Keymaster

      Hi,

      Please use this revised code –

      function wcfm_max_image_size( $file ) {
       
        $img     = getimagesize($file['tmp_name']);
      	$minimum = array( 'min_width' => '600', 'max_width' => '1200', 'height' => '600');
      	$width   = $img[0];
      	$height  = $img[1];
      
      	if ($width > $minimum['max_width'] )
      		return array("error"=>"Image dimensions are too large. Maximum width is {$minimum['max_width']}px. Uploaded image width is $width px");
      	elseif ($width < $minimum['min_width'] )
      		return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['min_width']}px. Uploaded image width is $width px");
      	elseif ($height >  $minimum['height'])
      		return array("error"=>"Image dimensions are too large. Maximum height is {$minimum['height']}px. Uploaded image height is $height px");
      	elseif ($height <  $minimum['height'])
      		return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
      	else
      		return $file; 
        
        return $file;
      }
      add_filter( 'wp_handle_upload_prefilter', 'wcfm_max_image_size' );

      Thank You

    • #41140
      MOHO
      Participant

      could i add ‘max_height’ => ‘1200’ ??

      Minimum height 600px
      Maximum height 1200px

    • #41144
      WCFM Forum
      Keymaster

      HI,

      Sure, please use this revised code –

      function wcfm_max_image_size( $file ) {
       
        $img     = getimagesize($file['tmp_name']);
      	$minimum = array( 'min_width' => '600', 'max_width' => '1200', 'height' => '600', 'max_height' => '1200' );
      	$width   = $img[0];
      	$height  = $img[1];
      
      	if ($width > $minimum['max_width'] )
      		return array("error"=>"Image dimensions are too large. Maximum width is {$minimum['max_width']}px. Uploaded image width is $width px");
      	elseif ($width < $minimum['min_width'] )
      		return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['min_width']}px. Uploaded image width is $width px");
      	elseif ($height >  $minimum['max_height'])
      		return array("error"=>"Image dimensions are too large. Maximum height is {$minimum['max_height']}px. Uploaded image height is $height px");
      	elseif ($height <  $minimum['height'])
      		return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
      	else
      		return $file; 
        
        return $file;
      }
      add_filter( 'wp_handle_upload_prefilter', 'wcfm_max_image_size' );

      Thank You

    • #41285
      MOHO
      Participant

      I didn’t know why it not work for your new code
      http://mall.sites.moho.tw/admin/products-manage/

    • #41316
      WCFM Forum
      Keymaster

      Hi,

      None of these conditions are working for you?

      Thank You

    • #41318
      MOHO
      Participant

      the last one code not work, i will try again

    • #41324
      WCFM Forum
      Keymaster

      Strange! Code is perfect.

      Hope you are uploading an image which has height more than 1200?

      Can you send me that image?

      Thank You

    • #41328
      MOHO
      Participant

      this image

      Attachments:
      You must be logged in to view attached files.
    • #41331
      WCFM Forum
      Keymaster

      Hi,

      Conditions are checking one by one.

      And this image restricted by it’s large width – https://ibb.co/PMkkNgL
      Height checking not executed.

      Thank You

    • #41459
      MOHO
      Participant

      i see it work, thanks.

      and could change this?

      “height –> min_height”

      It will be good for manage, thanks.

    • #41464
      WCFM Forum
      Keymaster

      Hi,

      “height –> min_height”

      – What change? Height check before max-height check?

      Thank You

    • #41473
      MOHO
      Participant

      Just change name, could it?
      because you use “min_width”, i want “height” change to “min_height”

      Attachments:
      You must be logged in to view attached files.
    • #41522
      WCFM Forum
      Keymaster

      OK, understand.

      Here is modified code –

      function wcfm_max_image_size( $file ) {
       
        $img     = getimagesize($file['tmp_name']);
      	$minimum = array( 'min_width' => '600', 'max_width' => '1200', 'min_height' => '600', 'max_height' => '1200' );
      	$width   = $img[0];
      	$height  = $img[1];
      
      	if ($width > $minimum['max_width'] )
      		return array("error"=>"Image dimensions are too large. Maximum width is {$minimum['max_width']}px. Uploaded image width is $width px");
      	elseif ($width < $minimum['min_width'] )
      		return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['min_width']}px. Uploaded image width is $width px");
      	elseif ($height >  $minimum['max_height'])
      		return array("error"=>"Image dimensions are too large. Maximum height is {$minimum['max_height']}px. Uploaded image height is $height px");
      	elseif ($height <  $minimum['min_height'])
      		return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['min_height']}px. Uploaded image height is $height px");
      	else
      		return $file; 
        
        return $file;
      }
      add_filter( 'wp_handle_upload_prefilter', 'wcfm_max_image_size' );

      Thank You

Viewing 18 reply threads
  • The topic ‘How could i limit store vendor only upload 600 x 600 px image at product?’ is closed to new replies.