there are various options. an application aimed to accomplish that task, as 6StringGeek mentioned. if you have PhotoShop, or a similar application, you can use or create a batch to be applied on a directory. or you can even write a script for PhotoShop so you can detect the orientation. another solution is PHP. if you are very well proficient in the language, you can write a script that use the image library bundled in PHP to resize and optimize images on a directory.