Home Support General HivePress Crop vs resize?

Crop vs resize?

  • Author
    Posts
  • Gsantos602

    Hello,

    I was curious if it was possible to resize the images uploaded instead of cropping them. My users upload both portrait and landscape and the cropping is hard to manage. I was hoping you could provide some direction where images are automatically resized to the max allowed width, with respect to ratio?

    ihor developer

    Sure, you can override these settings via the HivePress API:

    add_filter(
    	'hivepress/v1/image_sizes',
    	function( $args ) {
    		return array_merge(
    			$args,
    			[
    			// custom settings here.
    			]
    		);
    	}
    );

    Please check the existing settings here https://github.com/hivepress/hivepress/blob/master/includes/configs/image-sizes.php You can simply copy them and change the parameters (check the available parameters here https://developer.wordpress.org/reference/functions/add_image_size/).

    Gsantos602

    Hello, thank you for your speedy reply. I was trying to do:

    add_filter(
    	'hivepress/v1/image_sizes',
    	function( $args ) {
    		return array_merge(
    			$args,
    			[
    				'full' => [
    				],
    			]
    		);
    	}
    );
    

    I am not having luck. This also might work as a feature. A button to enable cropping? I played around with the CSS and if the image is in full in the body on your theme, then the image will be constrained to the allowed width. I appreciate any help, thank you.

    Gsantos602

    I did also try this

    
    	'full'    => [
    		'width'  => 0,
    		'height' => 0,
    		'crop'   => false,
    	],
    
    ihor developer

    This one should work, if you mean disable height cropping for the listing gallery images:

    add_filter(
    	'hivepress/v1/image_sizes',
    	function( $args ) {
    		return array_merge(
    			$args,
    			[
    				'landscape_large' => [
    					'width'  => 800,
    					'height' => 9999,
    					'crop'   => true,
    				],
    			]
    		);
    	}
    );

    Please note that this will be applied to new images only, you can also regenerate existing images https://wordpress.org/plugins/regenerate-thumbnails/

    Gsantos602

    Thanks for the suggestion, but that didn’t quite get what I was looking for.

    In your plugin code: hivepress/templates/listing/view/page/listing-images.php

    
    defined( 'ABSPATH' ) || exit;
    
    if ( $listing->get_images__url( 'hp_landscape_large' ) ) :
    	?>
    	<div class="hp-listing__images" data-component="carousel-slider">
    		<?php foreach ( $listing->get_images__url( 'hp_landscape_large' ) as $image_url ) : ?>
    			<img src="<?php echo esc_url( $image_url ); ?>" alt="<?php echo esc_attr( $listing->get_title() ); ?>">
    		<?php endforeach; ?>
    	</div>
    	<?php
    endif;
    
    

    I was able to replace
    hp_landscape_large
    with
    full
    and got the results I was looking for. I’m familiar enough with code to know that’s not a place I should be editing, but not familiar enough to do it with a filter. Thank you for your help.

    Gsantos602

    I replaced it within the For loop, not in the initial function*

    ihor developer

    Please make sure that you added the code snippet correctly, it’s the best way to override the image settings. The solution you chose will cause 2 issues:

    – It’ll get erased on update (if you edited the plugin file directly)
    – If someone uploads a huge image, like 2000px in width, then the listing page will be really slow (since ‘full’ mode doesn’t have any resizing).

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Subscribe

Sign In

Don't have an account? Register

Forgot password?

Register

Already have an account? Sign In

Forgot password?

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.