Rotate text image to portrait in Linux

Using Xojo 2024 r1
How do I rotate an image of text. I need to detect the current orientation and then rotate it to 0.
I tried passing this to a shell command but it does not work. (no output). It does not have to be done in a command line. I just need to rotate the png image and then save the new rotated png image. Then a new text file will be created using Tesseract and that text is sent to chatgpt. I know that some of you are doing OCR, please help if you can. Or if you know a better way?
It starts out as a scanned pdf file, I use pdftoppm to extract the images.
Thanks

e = "for i in " + newpng.shellpath + "*.png; do tesseract ""$i"" " + newpng.shellpath + "output --psm 0 -c tessedit_create_txt=1 orientation=$(grep ""Orientation in degrees"" " + newpng.shellpath + "output.txt | awk '{print $5}') convert ""$i"" -rotate -$orientation " + newpng.shellpath + "output.png"
s.Execute(e)

For anyone that has the same question. Here is the command line that will rotate the images after they are extracted from the pdf file using pdftoppm.
This is on Linux but can be used on Windows if you install all the correct programs.

e = "for i in " + newpng.shellpath + "*.png; do tesseract ""$i"" ""$i"" --psm 0 && orientation=$(grep ""Rotate:"" ""${i}.osd"" | awk '{print $2}') && convert ""$i"" -rotate $orientation ""$i"" && tesseract ""$i"" ""$i"" --psm 1 --dpi 150; done"
s.Execute(e)
e = "rm " + newpng.shellpath + "*.png " + newpng.shellpath + "*.png.osd"
s.execute(e)