Here's a short function for fish shell I am currently using to merge photos into one pdf and then optimize it to massively reduce the resulting size, for instance from 13MB to 230kB without loosing too much quality. Works for me very well, requires GhostScript and ImageMagick 7 or higher: