folder icon from image inside

hi all,
i’m looking fo a script or automator action which copy & past an image inside a folder named cover and paste it as folder preview icon (512 x 512 px) at the same folder. If possible just copy a square crop of the middle of the image.

i’ve found already a folder action which do something similar, but i wasn’t happy with the icon style.

hope somebody has a solution for me. i don’t want to do it by hand for every single folder.

greets