Hi @kayapati
You can try this filter hook to customize the size:
+ um_upload_image_process__profile_photo
Parameters:
– $response
– $image_path
– $src
– $key
– $user_id
– $coord
– $crop
Regards,
Hi @kayapati
Here’s the code snippet:
<?php
add_filter("um_upload_image_process__profile_photo","um_custom_profile_photo_size", 1, 7 );
function um_custom_profile_photo_size( $response, $image_path, $src, $key, $user_id, $coord, $crop ){
$quality = UM()->options()->get( 'image_compression' );
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
$temp_image_path = $image_path;
//refresh image_path to make temporary image permanently after upload
$image_path = pathinfo( $image_path, PATHINFO_DIRNAME ) . DIRECTORY_SEPARATOR . $key . '-custom.' . pathinfo( $image_path, PATHINFO_EXTENSION );
if ( ! is_wp_error( $image ) ) {
$image->resize( 200, 600, true );
$image->set_quality( $quality );
$image->save( $image_path );
}
}
?>
Regards,
Thank you very much for the code, but I am a designer and can you tell me where this code should go?
Hi @kayapati
You can add it to your Theme’s functions.php file but be cautious when adding it without understanding the opening-closing PHP tags.
Ensure that you’ve created a full backup of your site before you add the code.
Regards,
I already added it, but where I see results? I can not see any changes while uploading profile image? where I can I see the changes?
Hi @kayapati
You can check the uploads folder wp-content/uploads/ultimatemember/ and see if it has generated the custom size for your custom grid templates.
Regards,
Great, I see the image is cropped with specified sizes.
But here 2 minor issues.
1. When I upload profile image, the Media uploader keep on getting the text message “Keep Processing” when I cancel and save the page the profile image is appear, is any thing missing in the code?
2. I see the image in “wp-content/uploads/ultimatemember/6/profile_photo-custom.jpg” how to display it in my custom profile template.
I am trying to know the path of the image but not getting, can you tell me how to display the image either in member-grid.php which I located in my theme to customize it as per my needs.
Thank you for your help.
Hi @kayapati
You only need the user ID to display the custom profile photo:
<img src="https://www.yoursite.com/wp-content/uploads/ultimatemember/<insert user id>/profile_photo-custom.jpg"></a>
Regards,
Hi @kayapati
You can add the following code:
$image_path = str_replace("/uploads/ultimatemember/","/uploads/sites/151/ultimatemember/", $image_path );
After this code:
$image_path = pathinfo( $image_path, PATHINFO_DIRNAME ) . DIRECTORY_SEPARATOR . $key . '-custom.' . pathinfo( $image_path, PATHINFO_EXTENSION );
Regards,
-
This reply was modified 6 years, 6 months ago by
Champ Camba.
I have added the above code, but it still not working.
Check this my live site you can see the image not working above the original image.
THis is my live site:
https://kayapati.com/demos/alexia/user/ramram/
Check this image draft
-
This reply was modified 6 years, 6 months ago by
kayapati.
Hi @kayapati
How do you display the profile photo with custom size? Do you add it directly to the custom Profile Template?
Regards,
no, I am using Custom Template but the action hook is same. I just custom Template for styling purpose.
This is the code from which the profile photo is coming.
do_action( ‘um_profile_header’, $args );
Sorry, ignore the above message,
The below code in theme function.php
add_filter("um_upload_image_process__profile_photo","um_custom_profile_photo_size", 1, 7 );
function um_custom_profile_photo_size( $response, $image_path, $src, $key, $user_id, $coord, $crop ){
$quality = UM()->options()->get( 'image_compression' );
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
$temp_image_path = $image_path;
//refresh image_path to make temporary image permanently after upload
$image_path = pathinfo( $image_path, PATHINFO_DIRNAME ) . DIRECTORY_SEPARATOR . $key . '-custom.' . pathinfo( $image_path, PATHINFO_EXTENSION );
$image_path = str_replace("/uploads/ultimatemember/","/uploads/sites/151/ultimatemember/", $image_path );
if ( ! is_wp_error( $image ) ) {
$image->resize( 275, 325, true );
$image->set_quality( $quality );
$image->save( $image_path );
}
}
and the below one added in custom template.
$profile_image_path = um_user_uploads_uri() . ('profile_photo-custom.jpg');
echo "<img src=".esc_attr ($profile_image_path).">";
This is working fine with local server. but when I upload into my live site which is mutlinetwork, not working.
-
This reply was modified 6 years, 6 months ago by
kayapati.