namespace eval ::ThreadedResize {
global auto_path
variable th 

	package provide ThreadedResize 0.1	
	
	package require Thread
	package require Img
	
	tsv::set application apath $auto_path
	
	set th [thread::create]
	
	thread::send $th {set auto_path [tsv::get application apath]}
	thread::send $th {package require Tk}
	thread::send $th {package require Img}
	thread::send $th {package require resize}
	thread::send $th {wm withdraw .}
}

proc ::ThreadedResize::resize { img newx newy} {
global configdir
variable th 
	
	set file_im [file join $configdir winup-image-temp]
	$img write $file_im
	
	thread::send $th "set img \[image create photo\]"
	thread::send $th "\$img read $file_im"
	
	thread::send -async $th "::resize::resize \$img $newx $newy" \
		::vwait_result
	vwait ::vwait_result
	
	set img $::vwait_result
	
	thread::send $th [list $img write $file_im]
	
	set result [image create photo] 
	$result read $file_im
	
	return $result
}