Rename Contents to Folder Name?

I have a bunch of .jpg files with randomly generated names, each contained within a folder with the correct name the file should have.
Is it possible to have Hazel rename all .jpg files to the containing folder name, then move that file one folder up so I have all the files in one folder together instead of hundreds?
Thanks in advance!
Is it possible to have Hazel rename all .jpg files to the containing folder name, then move that file one folder up so I have all the files in one folder together instead of hundreds?
Thanks in advance!