php - Add filter when image is uploaded?

I'm trying to use this code from another SO resopnse:function ajx_sharpen_resized_files( $resized_file ) {$image =

I'm trying to use this code from another SO resopnse:

function ajx_sharpen_resized_files( $resized_file ) {

    $image = wp_load_image( $resized_file );
    if ( !is_resource( $image ) )
        return new WP_Error( 'error_loading_image', $image, $file );

    $size = @getimagesize( $resized_file );
    if ( !$size )
        return new WP_Error('invalid_image', __('Could not read image size'), $file);
    list($orig_w, $orig_h, $orig_type) = $size;

    switch ( $orig_type ) {
        case IMAGETYPE_JPEG:
            $matrix = array(
                array(-1, -1, -1),
                array(-1, 16, -1),
                array(-1, -1, -1),
            );

            $divisor = array_sum(array_map('array_sum', $matrix));
            $offset = 0; 
            imageconvolution($image, $matrix, $divisor, $offset);
            imagejpeg($image, $resized_file,apply_filters( 'jpeg_quality', 90, 'edit_image' ));
            break;
        case IMAGETYPE_PNG:
            return $resized_file;
        case IMAGETYPE_GIF:
            return $resized_file;
    }

    return $resized_file;
}   

add_filter('image_make_intermediate_size', 'ajx_sharpen_resized_files',900);

It works well but is only executing for when WP uses image_make_intermediate_size. Would there be a way to make this apply for every image that is uploaded?

Thanks

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745609208a4635849.html

相关推荐

  • php - Add filter when image is uploaded?

    I'm trying to use this code from another SO resopnse:function ajx_sharpen_resized_files( $resized_file ) {$image =

    11小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信