Viewing 30 posts - 1 through 30 (of 31 total)
  • Author
    Posts
  • #1254990

    Hi,
    we added new image sizes through the function below.

    add_action( 'after_setup_theme', 'my_custom_image_sizes' );
    
    function my_custom_image_sizes() {
    if ( function_exists( 'add_image_size' ) ) {
      //Header Titelbild 1920 x 700	
      add_image_size( 'header-top', 1920, 700, array('center', 'top') );
      add_image_size( 'header-center', 1920, 701, array('center', 'center') );
      add_image_size( 'header-bottom', 1920, 702, array('center', 'bottom') );
      
      //Trennerbild 1920 x 500
      add_image_size( 'trenner-top', 1920, 500, array('center', 'top') );
      add_image_size( 'trenner-center', 1920, 501, array('center', 'center') );
      add_image_size( 'trenner-bottom', 1920, 502, array('center', 'bottom') );
      
      //Bild Spalte 1/1 800 x 450
      add_image_size( 'bild-content-1-1', 800, 450 );
      
      //Bild Spalte 1/2 650 x 366
      add_image_size( 'bild-content-1-2', 650, 366 );
    
      //Newsbereich 450 x 253
      add_image_size( 'bild-news', 450, 253 );
      
      //Thumbnails für Menü 334 x 188
      add_image_size( 'menu-thumbnails', 334, 188 );  
     }
    }
    
    add_filter( 'image_size_names_choose', 'my_custom_sizes' );
    
    function my_custom_sizes( $sizes ) {
    return array_merge( $sizes, array(
        'header-top' => __('Header Top 1920x700'),
    	'header-center' => __('Header Center 1920x700'),
    	'header-bottom' => __('Header Bottom 1920x700'),
    	'trenner-top' => __('Trenner Top 1920x500'),
    	'trenner-center' => __('Trenner Center 1920x500'),
    	'trenner-bottom' => __('Trenner Bottom 1920x500'),
    	'bild-content-1-1' => __('Bild Content 1/1 800x450'),
    	'bild-content-1-2' => __('Bild Content 1/2 650x366'),
    	'bild-news' => __('Newsbereich 450x253'),
    	'menu-thumbnails' => __('Menü Thumbnails 334x188')
    ) 

    We want to have different cropped versions of the same image size. The Problem ist that the uploaded image name is always the same (image-1920×700). Can this be changed?
    We had something in mind like adding a letter for each cropped version like image-1920x700c (c=center). Would this be possible?

    Looking forward to any solution for this.

    Thanks in advance,
    Sebastian

    #1255955

    Hey emilconsor,

    Thank you for the inquiry.

    Please try to adjust the priority value of the image_size_names_choose filter to 9999.

    add_action( 'after_setup_theme', 'avf_custom_image_sizes' );
    
    function avf_custom_image_sizes() {
    	if ( function_exists( 'add_image_size' ) ) {
    		//Header Titelbild 1920 x 700	
    		add_image_size( 'header-top', 1920, 700, array('center', 'top') );
    		add_image_size( 'header-center', 1920, 701, array('center', 'center') );
    		add_image_size( 'header-bottom', 1920, 702, array('center', 'bottom') );
    
    		//Trennerbild 1920 x 500
    		add_image_size( 'trenner-top', 1920, 500, array('center', 'top') );
    		add_image_size( 'trenner-center', 1920, 501, array('center', 'center') );
    		add_image_size( 'trenner-bottom', 1920, 502, array('center', 'bottom') );
    
    		//Bild Spalte 1/1 800 x 450
    		add_image_size( 'bild-content-1-1', 800, 450 );
    
    		//Bild Spalte 1/2 650 x 366
    		add_image_size( 'bild-content-1-2', 650, 366 );
    
    		//Newsbereich 450 x 253
    		add_image_size( 'bild-news', 450, 253 );
    
    		//Thumbnails für Menü 334 x 188
    		add_image_size( 'menu-thumbnails', 334, 188 );  
    	}
    }
    
    add_filter( 'image_size_names_choose', 'avf_image_size_names_choose_mod', 9999 );
    
    function avf_image_size_names_choose_mod( $sizes ) {
    	return array_merge( $sizes, array(
    		'header-top' => __('Header Top 1920x700', 'avia_framework'),
    		'header-center' => __('Header Center 1920x700', 'avia_framework'),
    		'header-bottom' => __('Header Bottom 1920x700', 'avia_framework'),
    		'trenner-top' => __('Trenner Top 1920x500', 'avia_framework'),
    		'trenner-center' => __('Trenner Center 1920x500', 'avia_framework'),
    		'trenner-bottom' => __('Trenner Bottom 1920x500', 'avia_framework'),
    		'bild-content-1-1' => __('Bild Content 1/1 800x450', 'avia_framework'),
    		'bild-content-1-2' => __('Bild Content 1/2 650x366', 'avia_framework'),
    		'bild-news' => __('Newsbereich 450x253', 'avia_framework'),
    		'menu-thumbnails' => __('Menü Thumbnails 334x188', 'avia_framework')
    	));
    }
    

    Best regards,
    Ismael

    #1257647

    Hi Ismael,
    thanks for your reply.
    Unfortunately this will not set all the responsive image sizes within the srcset attribute.
    We found this code in the theme documentation and tested it. So far it’s working great. But its not described how to set the crop position. Is this posibile? And also we still want the images to have unique names like described above.

    /**
     * Allow to change or add definition of themes registered image sizes
     * ==================================================================
     * 
     * see enfold\functions.php around line 146ff for theme defined image sizes
     * 
     * You need to regenerate the WP generated thumbnails with a plugin like 
     * 
     * https://wordpress.org/plugins/regenerate-thumbnails/
     * https://de.wordpress.org/plugins/regenerate-thumbnails/
     * 
     * when you modify image sizes.
     * 
     * 
     * Copy the following snippets in functions.php and modify to your needs
     * 
     * @param array $sizes              
     * @return array                
     * 
     * @version 1.1.0
     * @since Enfold 3.0  ??
     */
    
    /**
     * Add or modify image sizes
     * 
     * @param array $sizes
     * @return array
     */
    function custom_modified_thumb_sizes( array $sizes )
    {
      /**
       * Example: Change sizes for 'masonry'
       * 
       */
                //  set to true to crop images (= default value if not set)
      //$sizes['masonry'] = array( 'width' => 1024, 'height' => 1024, 'crop' => false );
      
      /**
       * Example: Add new size for 'my_custom_size'
       */
      $sizes['test_img_size'] = array( 'width' => 800, 'height' => 450, 'crop' => true );
      $sizes['test_img_size_tab'] = array( 'width' => 650, 'height' => 366, 'crop' => true );
      
      return $sizes;
    }
    
    /**
     * Add or remove selectable image sizes
     * 
     * @since 4.7.5.1
     * @param array $selectableImgSize
     * @param array $imgSizes
     * @return array
     */
    function custom_modify_selectable_image_sizes( array $selectableImgSize, array $imgSizes ) 
    {
      /**
       * Example: Add my_custom_size registered before
       */
      $selectableImgSize['test_img_size'] = 'Test Bildgröße';
      $selectableImgSize['test_img_size_tab'] = 'Test Bildgröße Tab';
      
      /**
       * Example: Remove an image size 
       */
      unset( $selectableImgSize['extra_large'] );
      
      return $selectableImgSize;
    }
    
    /**
     * Add additional human readable image sizes (prepared in case we allow to add custom image sizes by theme)
     * 
     * @since 4.7.5.1
     * @param array $readableImgSizes
     * @param array $imgSizes
     * @return array
     */
    function custom_modify_readable_image_sizes( array $readableImgSizes, array $imgSizes ) 
    {
      /**
       * Example: Add my_custom_size registered before
       */
      $readableImgSizes['test_img_size'] = 'Test Bildgröße';
      $readableImgSizes['test_img_size_tab'] = 'Test Bildgröße Tab';
      
      return $readableImgSizes;
    }
    
    add_filter( 'avf_modify_thumb_size', 'custom_modified_thumb_sizes', 10, 1 );
    add_filter( 'avf_modify_selectable_image_sizes', 'custom_modify_selectable_image_sizes', 10, 2 );
    add_filter( 'avf_modify_readable_image_sizes', 'custom_modify_readable_image_sizes', 10, 2 );

    Best regards,
    Sebastian

    #1258533

    Hi,

    Thank you for the update.

    For the crop position, instead of returning true or false, we have to return an array containing the crop positions (x and y axis) as described in the documentation.

    // https://developer.wordpress.org/reference/functions/add_image_size/#crop-mode

    Best regards,
    Ismael

    #1258543

    Hi Ismael,

    thanks for the advice :)

    Is it possible to get unique names for the images when using the same size?

    For example we’re having the size 1920x700px and we want to make two crop positions selectable for this size, so we can choose between those two images. Right now the cropped image gets the size as addition at the end (header-intro-1920×700). Is it possible to give the image name another addition like header-intro-1920×700-leftright or something like that?

    Best regards,
    Sebastian

    #1259152

    Hi,

    Thank you for for following up.

    Is it possible to give the image name another addition like header-intro-1920×700-leftright or something like that?

    You will have to register another thumbnail for the other image with a different crop position.

    Best regards,
    Ismael

    #1259193

    Hi,
    yeah, I know but the thumbnail name ist always created with the resolution as addition.

    imgname-1920×700 (crop, left, top)
    imgname-1920×700 (crop, right, center)

    This wont work because only one image at a time can have the same name. So what we need is a solution that adds another addition which stands for the crop position.

    So we need something like this,

    imgname-1920×700-lefttop (crop, left, top)
    imgname-1920×700-rightcenter (crop, right, center)

    so we can use the same image with different crop positions.

    Regards,
    Sebastian

    #1259525

    Hi,

    That is why you have to register another thumbnail with a different name for the image with a different crop position. Both thumbnails will have the same height and width, but they should not have the same name when you register them.

    Best regards,
    Ismael

    #1259573

    Hi Ismael,
    ok, so am I doing something wrong?
    This is the code in the functions.php

    function custom_modified_thumb_sizes( array $sizes )
    {
      /**
       * Example: Change sizes for 'masonry'
       * 
       */
                //  set to true to crop images (= default value if not set)
      //$sizes['masonry'] = array( 'width' => 1024, 'height' => 1024, 'crop' => false );
      
      /**
       * Example: Add new size for 'my_custom_size'
       */
      $sizes['divide_img_top_center'] = array( 'width' => 1920, 'height' => 500, array('top','center') );
      $sizes['divide_img_center_center'] = array( 'width' => 1920, 'height' => 500, array('center','center') );
      $sizes['divide_img_bottom_center'] = array( 'width' => 1920, 'height' => 500, array('bottom','center') );
      
      return $sizes;
    }
    
    /**
     * Add or remove selectable image sizes
     * 
     * @since 4.7.5.1
     * @param array $selectableImgSize
     * @param array $imgSizes
     * @return array
     */
    function custom_modify_selectable_image_sizes( array $selectableImgSize, array $imgSizes ) 
    {
      /**
       * Example: Add my_custom_size registered before
       */
      
      $selectableImgSize['divide_img_top_center'] = 'Trenner Bild (Top)';
      $selectableImgSize['divide_img_center_center'] = 'Trenner Bild (Center)';
      $selectableImgSize['divide_img_bottom_center'] = 'Trenner Bild (Bottom)';
      
      /**
       * Example: Remove an image size 
       */
      unset( $selectableImgSize['extra_large'] );
      
      return $selectableImgSize;
    }
    
    /**
     * Add additional human readable image sizes (prepared in case we allow to add custom image sizes by theme)
     * 
     * @since 4.7.5.1
     * @param array $readableImgSizes
     * @param array $imgSizes
     * @return array
     */
    function custom_modify_readable_image_sizes( array $readableImgSizes, array $imgSizes ) 
    {
      /**
       * Example: Add my_custom_size registered before
       */
      
      $readableImgSizes['divide_img_top_center'] = 'Trenner Bild (Top)';
      $readableImgSizes['divide_img_center_center'] = 'Trenner Bild (Center)';
      $readableImgSizes['divide_img_bottom_center'] = 'Trenner Bild (Bottom)';
      
      return $readableImgSizes;
    }
    
    add_filter( 'avf_modify_thumb_size', 'custom_modified_thumb_sizes', 10, 1 );
    add_filter( 'avf_modify_selectable_image_sizes', 'custom_modify_selectable_image_sizes', 10, 2 );
    add_filter( 'avf_modify_readable_image_sizes', 'custom_modify_readable_image_sizes', 10, 2 );

    If i then select the different sizes in the backend it outputs the same image for each section.

    See this screenshot: Source Code
    Also the size is not shown correct: size Selection
    The size in the code is 1900×500 but the dropdown shows 1500×391.

    Do I have to change something in the functions or why is this not working yet?

    Best regards,
    Sebastian

    #1260538

    Hi,

    Sorry for the delay. Looks like the original or full sized version of the image is used in the page. What is the size of the original image?

    Could you provide access to the site so that we could check it properly? Please post the site details in the private field

    Best regards,
    Ismael

    #1260718

    Hi Ismael,

    no, the original size is 1920x1275px.

    I’ve created you a temporary login.

    Best regards,
    Sebastian

    #1261470

    Hi,

    Did you upload the original image again or regenerate the images after the thumbnail registration?

    This is probably not working as it should because the new thumbnails’ x_crop_position or the first value in the array is invalid. The valid values are ‘left’ ‘center’, or ‘right’.

      $sizes['divide_img_top_center'] = array( 'width' => 1920, 'height' => 500, array('top','center') );
      $sizes['divide_img_center_center'] = array( 'width' => 1920, 'height' => 500, array('center','center') );
      $sizes['divide_img_bottom_center'] = array( 'width' => 1920, 'height' => 500, array('bottom','center') );
    

    So top-center and bottom-center is not correct, and should be center-top and center-bottom.

    Best regards,
    Ismael

    #1261481

    Hi Ismael,

    i used a different image every time (fresh upload). Is it only working when regenerate thumbnail is used? I thought it would work for any fresh uploaded image and only for already uploaded images you have to use the regenerate?

    I’ve changed the invalid values and uploaded a new image. The Label in the select dropdown still shows the wrong reoslution for the images.
    The image ist still the same even if i select a different size for each one of the three images in this pages.

    So what am I doing wrong, or is it just not working the way i suppose it to be?

    Best regards,
    Sebastian

    #1262238

    Hi,

    It should regenerate new thumbnails when you upload the images again after the code adjustment, but make sure to purge the server and plugin cache before doing so because the old thumbnails might still be in used instead of the updated ones.

    Could you post the updated code? Have you tried adjusting the size of the other thumbnails a bit so that they are completely different? Just add or subtract a pixel for the width and height and update the first value in the array so that they are valid.

    Best regards,
    Ismael

    #1262358

    Hey,
    here is the updated code:

    function custom_modified_thumb_sizes( array $sizes )
    {
      /**
       * Example: Change sizes for 'masonry'
       * 
       */
                //  set to true to crop images (= default value if not set)
      //$sizes['masonry'] = array( 'width' => 1024, 'height' => 1024, 'crop' => false );
      
      /**
       * Example: Add new size for 'my_custom_size'
       */
      $sizes['divide_img_top_center'] = array( 'width' => 1920, 'height' => 500, array('center','top') );
      $sizes['divide_img_center_center'] = array( 'width' => 1920, 'height' => 501, array('center','center') );
      $sizes['divide_img_bottom_center'] = array( 'width' => 1920, 'height' => 499, array('center','bottom') );
      
      return $sizes;
    }
    
    /**
     * Add or remove selectable image sizes
     * 
     * @since 4.7.5.1
     * @param array $selectableImgSize
     * @param array $imgSizes
     * @return array
     */
    function custom_modify_selectable_image_sizes( array $selectableImgSize, array $imgSizes ) 
    {
      /**
       * Example: Add my_custom_size registered before
       */
      
      $selectableImgSize['divide_img_top_center'] = 'Trenner Bild (Top)';
      $selectableImgSize['divide_img_center_center'] = 'Trenner Bild (Center)';
      $selectableImgSize['divide_img_bottom_center'] = 'Trenner Bild (Bottom)';
      
      /**
       * Example: Remove an image size 
       */
      //unset( $selectableImgSize['extra_large'] );
      
      return $selectableImgSize;
    }
    
    /**
     * Add additional human readable image sizes (prepared in case we allow to add custom image sizes by theme)
     * 
     * @since 4.7.5.1
     * @param array $readableImgSizes
     * @param array $imgSizes
     * @return array
     */
    function custom_modify_readable_image_sizes( array $readableImgSizes, array $imgSizes ) 
    {
      /**
       * Example: Add my_custom_size registered before
       */
      
      $readableImgSizes['divide_img_top_center'] = 'Trenner Bild (Top)';
      $readableImgSizes['divide_img_center_center'] = 'Trenner Bild (Center)';
      $readableImgSizes['divide_img_bottom_center'] = 'Trenner Bild (Bottom)';
      
      return $readableImgSizes;
    }
    
    add_filter( 'avf_modify_thumb_size', 'custom_modified_thumb_sizes', 10, 1 );
    add_filter( 'avf_modify_selectable_image_sizes', 'custom_modify_selectable_image_sizes', 10, 2 );
    add_filter( 'avf_modify_readable_image_sizes', 'custom_modify_readable_image_sizes', 10, 2 );
    

    The sizes show up correct in the theme options but if i then select them in the layout builder the crop position isn’t correct. Is there a problem with the code above?

    Thanks,
    Sebastian

    #1263159

    Hi,

    The code above looks correct, the values of the crop parameter are valid. Did you purge the cache and regenerate the thumbnails after editing the code?

    We would like to test this again but the login token above seems to have expired. Please create another token, or post the WP and FTP details in the private field so that we could test the site properly.

    Thank you for your patience.

    Best regards,
    Ismael

    #1263209

    Hi,
    yes, I always do that.

    But I’ve uploaded new images so it should not be necessary to regenerate the thumbnails, as discussed before.

    I’ve reactivated the access link. See private content.
    Unfortunately I can’t grant u ftp access.

    Thanks in advance.

    Regards,
    Sebastian

    #1263452

    Hi,

    Unfortunately, we will not be able to help properly if we cannot edit the files and test the modification. Please allow file editing in the Appearance > Editor panel at least so that we could edit the snippet and do the necessary changes. And aside from updating the height values, try to also adjust the width values as well so that the thumbnails are completely different from each other.

    Best regards,
    Ismael

    #1263464

    Hi Ismael,

    I’ve activated the editor. Feel free to edit the functions.

    Thanks,
    Sebastian

    #1263849

    Hi,

    Thank you for the update.

    We adjusted the height values a bit and uploaded an image with 3 different colors but it did not work. Looks like there is an issue with the image cropping option because when we visited an official documentation or article about WP images, the examples are cropped the same way even though they are supposed to show in different crop positions.

    // https://havecamerawilltravel.com/photographer/wordpress-thumbnail-crop/

    UPDATE: We edited the custom_modified_thumb_sizes function and use the add_image_size function instead of modifying the existing thumbnails. It did not work at first because we were trying to modify thumbnails that do not actually exist. (see private field)

    Best regards,
    Ismael

    #1263887

    Hi Ismael,

    thanks for you effort. Looks good now.

    The last task ist just cosmetic but it would be nice, if this can also be fixed.
    Image size selection
    The Labels of the image size selection are still wring. Can you fix this?

    Thanks so far.

    Kind Regards,
    Sebastian

    #1264276

    Hi,

    That is odd. Have you tried removing the existing thumbnails and adding them again from scratch with totally different names?

    Thank you for your patience.

    Best regards,
    Ismael

    #1273606

    Hi Ismael,
    sorry for the late reply.

    I’m not sure what you mean with remove the existing thumbnails. The labels a wrong for every new uploaded image. Unfortunately it’s very confusing for the editors. Is this no common issue?
    Theme Options show the correct resolution but in the select dropdown when you upload images to media library there are completely different resolutions.

    Best regards,
    Sebastian

    #1274259

    Hi,

    I’m not sure what you mean with remove the existing thumbnails.

    Try to remove the uploaded image first from the Media > Library, before uploading it again. Or make sure that you are uploading different image each time for testing.

    This is not so common because most users do not require different cropping position for the same image. This might be the first request that we encountered.

    Best regards,
    Ismael

    #1274306

    Hi,

    sorry, but i don’t get it. What would it change if i upload a new img? The sizes which can be selected don’t change if i upload a new img.
    The size should be 1920 x 700 but this size woh is shown in the dropdown is not even close to this.

    View post on imgur.com

    Best Regards,
    Sebastian

    #1275158

    Hi,

    Looks like the image with a different cropping position does not display when the Performance > Responsive Image option enabled. Did you enable that option? It used to work in the test page before. (see private field)

    Best regards,
    Ismael

    #1275454

    Hi,

    yes, we enabled it but we did that when we installed the theme, so it was enabled all the time. I don’t know why it’s not working right now but the sizes in the dropdown select were wrong all the time since we added the new sizes.

    Regards,
    Sebastian

    #1275505

    Hi,

    we also wondering if it’s possible to set the compression for teh cropped images. That’s really necessary because some cropped images are larger than their original.

    Thanks,
    Sebastian

    #1275932

    Hi,

    You may need to disable the Responsive Images option if you want the images with different cropping position to actually display. For some reason, WP always selects the thumbnail with the default cropping position.

    And to adjust the compression level, please use this snippet in the functions.php file.

    
    // set the compression level of calculated images
    add_filter("avf_jpeg_quality", "avf_set_quality_mod", 9999, 1);
    add_filter("avf_wp_editor_set_quality", "avf_set_quality_mod", 9999, 1);
    function avf_set_quality_mod($quality) {
    	$quality = 65;   // compression level, default is 100
    	return $quality;
    }
    

    Best regards,
    Ismael

    #1276333

    Hi Ismael,
    we’ve disabled the responsive option and the imges get displayed with the correct cropping position in the page but in the dropdown the sizes are still wrong. Unfortunately the responsive thumbnails of the images don’t get loaded… is there a way where both can work together?

    We’ve insert the snippet and regnereated all thumbnails but the size didn’t change…

    Regards,
    Sebastian.

Viewing 30 posts - 1 through 30 (of 31 total)
  • You must be logged in to reply to this topic.