(function($){

    $.extend($.fn, {
        imageText : function ( o ) {

            var options = $.extend( {
                'font' : 'arial',
                'size' : 14,
                'color' : 'ffffff',
                'bgcolor' : '000000',
                'bg' : false,
                'align' : 'left', // left, center, right, left-adjust, center-adjust, right-adjust or adjust
                'valign' : 'top', // top, middle or bottom
                'width' : 'auto',
                'height' : 'auto',
                'line-height' : false,
                'x' : 0,
                'y' : 0,
                'padding' : false,
                'url' : '/img/imagetext.php'
            }, o || {} );

            return $(this).each(function(){
                var text = $(this).text();

                var width = ( options.width == 'auto' ? $(this).width() : options.width );
                var height = ( options.height == 'auto' ? $(this).height() : options.height );

                var $img = $('<img />').attr({
                    alt: text,
                    title: text,
                    src: options.url+"?w="+width+( options['line-height'] ? "&lh="+options['line-height'] : "&h="+height )+"&bgc="+options.bgcolor+"&c="+options.color+"&f="+options.font+"&s="+options.size+"&t="+encodeURIComponent(text)+"&x="+options.x+"&y="+options.y+( options.bg ? "&bg="+options.bg : "" )
                }).css({ display: 'block', 'float': 'none' });

                $(this).replaceWith( $img );
            });
        }
    });

})(jQuery);
