ENTRY

"WordPress image croping does only jpeg. Buddypress avatar cropping, uppload transparency problem"

Date:June 27th, 2014
Tags:
Comments: 3
  • Join date: 11-30-99
  • Posts: 23
View Counter:
  • 522 views
Rate it
Ad
Poll
  • In your own projects, what computer language(s) do you usually use?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

To enable cropping in buddypress, I had to fix the following issues:

In “Firefox Extras -> Error Console” watch for problems:
jQuery is not defined . Following should do the trick:

JQuery.Jcrop is not a function . Make sure that your site includes Jcrop library:

Now, the Jcrop library must go after jQuery, because it uses jQuery to do things.

The complication here is that many WordPress plugins do intervene with js inclusion so you end up with conflicts and doubling of libraries…

Then, there was:
“There was a problem cropping your avatar, please try uploading it again”

I used a nice fix, summed up by gian-ava:
(http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/avatar-cropping-after-upload-image-and-cropper-dont-appear-fails/)

START>>

– Go to Settings -> Miscellaneous Settings
– Set “Store uploads in this folder” to “wp-content/uploads”.
– Set “Full URL path to files” to the REAL FULL PATH of your uploads.

Then change bp-core-avatars.php line 389:

Replace:

1
2
if ( !$path = get_option( ‘upload_path’ ) )
$path = WP_CONTENT_DIR ./uploads’;

With:

1
2
3
if ( !$path = get_option( ‘upload_path’ ) )
$path = WP_CONTENT_DIR ./uploads’;
else $path = ABSPATH . $path;

>>END

Then, all transparency of my nice gifs and png’s was gone every time. That is because of the wordpress’s wp_crop_image function.
I end up with editing:
/wp-admin/includes/image.php wp_crop_image:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $destfilename = false ) {
 if ( is_numeric( $src_file ) ) // Handle int as attachment ID
  $src_file = get_attached_file( $src_file );
 
 $src = wp_load_image( $src_file );
 
 if ( !is_resource( $src ))
  return $src;
 
 $dst = wp_imagecreatetruecolor( $dst_w, $dst_h );
 
 if ( $src_abs ) {
  $src_w -= $src_x;
  $src_h -= $src_y;
 }
 
 list($width, $height, $orig_type) =  getimagesize( $src_file );
 
 if (function_exists('imageantialias'))
  imageantialias( $dst, true );
 
 imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
 
 imagedestroy( $src ); // Free up memory
 
// if ( ! $dst_file )
//  $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file );
 
        // convert from full colors to index colors, like original PNG.
        if ( IMAGETYPE_PNG == $orig_type && !imageistruecolor( $dst ) )
                imagetruecolortopalette( $dst, false, imagecolorstotal( $dst ) );
 
        if ( IMAGETYPE_GIF == $orig_type ) {
                if ( !imagegif( $dst, $destfilename ) )
                        return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
        } elseif ( IMAGETYPE_PNG == $orig_type ) {
                if ( !imagepng( $dst, $destfilename ) )
                       return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
      } else {
               if ( !imagejpeg( $dst, $destfilename, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
                       return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
       }
 
 //$dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
 
 //if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
//  return $dst_file;
// else
//  return false;
}

(Patch is here: http://trac.buddypress.org/attachment/ticket/1970/wp-admin-includes-image.patch)

Links:
http://deepliquid.com/content/Jcrop_Manual.html

Be Sociable, Share!
 
Interesting entry?
VN:F [1.8.5_1061]
Rating: +2 (from 2 votes)
2 votes 'YES'  0 votes 'NO'


TAGS
No tags for this post.

RELATED
Pages
Posts

SOCIAL
Be Sociable, Share!

INCOMING SEARCH TERMS



Responces

3 Responses to “WordPress image croping does only jpeg. Buddypress avatar cropping, uppload transparency problem”

  1. gurpreet says:

    Thank you so much it solved the big problem
    in my case png gets the black background
    Thanks

  2. Javi says:

    Thanks u very very much!

  3. Lego says:

    Thanks you very much!

Leave a Reply