using imagemagick for thumbnails (2 posts)

  1. tired
    Posted 9 years ago #


    I have this strange problem.. I upload photos from digital camera to my blog and the size is around >1.5mb.. and when I add it to blog using upload, the thumbnails created are very very small and when I post orignal image, its very large. Not sure how others are posting the images. I tried using this http://wordpress.org/support/topic/53019?replies=3 but somehow its not using imagemagick.. Anyidea on how to force the usage of imagemagick (convert) for uploaded images?


  2. adhoc
    Posted 9 years ago #

    I recently managed to use imagemagick instead of GD for converting images to thumbnails (I'm using the K2 theme, so I'm not sure if this will be tied to that theme or not). I replaced the code in wp_crop_image in wp-admin/admin-functions.php like this:

    function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
            if ( ctype_digit( $src_file ) ) // Handle int as attachment ID
                    $src_file = get_attached_file( $src_file );
            if ( $src_abs ) {
                    $src_w -= $src_x;
                    $src_h -= $src_y;
            if ( !$dst_file )
                    $dst_file = str_replace( basename( $src_file ), 'cropped-'.basename( $src_file ), $src_file );
            $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
            $cmd = sprintf("/sw/bin/convert %s -crop %dx%d+%d+%d -resize %dx%d %s",
            return $dst_file;

    Replace /sw/bin/convert with whereever your copy of convert is located.

    I have not investigated any other impacts this change may have on security etc.

    Good luck

Topic Closed

This topic has been closed to new replies.

About this Topic