Bash changing folder icons

Hey, so I have a folder of about +250 folders inside, each with a unique name. Now inside each folder is and .jpg named exactly the same as the folder it is in. What I am trying to do is change the folder icon for each folder to the image inside each folder. I WAS able to do this with applescript to go through each folder and a executable I found to change the icons. The only problem is that it converts the format of the picture or something, and distorts the image to the regular square icon instead of the original. I would like it to keep the original ratio dimensions.

Here’s the script I wrote:

set exePath to "Macintosh HD:Users:USERNAME:prog:AppleScript:SetFileIcon"

set mainFolder to (choose folder with prompt "Select Main Folder" default location "/Volumes/Entertainment/")

tell application "System Events" to set allFolders to POSIX path of folders of folder (POSIX path of mainFolder)

repeat with aFolder in allFolders
	set foldername to characters 30 thru -1 of aFolder
	tell application "Finder" to set imageFile to aFolder & foldername & ".jpg"
	do shell script quoted form of POSIX path of exePath & " -image " & quoted form of POSIX path of imageFile & " -file " & quoted form of POSIX path of aFolder
end repeat

display dialog "Done!"
beep 2

I have been looking around quite a lot and there doesn’t seem to be a surefire way to do it with multiple folders at once. I know it is pretty much impossible to use only AppleScript to do this, but does anyone know of a program or shell script that could accomplish my needs? The only other solution right now is to do them one at a time. Thanks in advance.