Implement vertical thumbs in custom post types

How to implement this snippets in custom post types

I'm trying to implement this snippet:

...but for custom post types. How can I do that?

I want a function that automatically identify when the height is greater than the width, then append a class CSS to display the image differently.