I'm trying to use a Display Suite field to wrap an image in a div.
What I also want to do is to htmlspecialchars on the token [node:field_mainimage].
It doesn't want to work for me. Is there any other way I can accomplish this?
Where are those images placed ?
If this is in content type, you can style the content type content by using custom tpl.php files and wrap your images in div there. (in sites/all/thems/yourtheme , that is.)
Also, you can create template files even for fields.
That gives you enormous power of controlling output :) .
It is bit "dirty", but you can also wrap images in div using jQuery. But first method is cleaner.
If you just want wrap image field formatter (html output of field) in another div (or other html containers) I recommend to use Field Group module.
It allows you in formatters configuration (admin/structure/types/manage/*/display) to group any fields and configure to wrap them by basic HTML wrappers, tabs, multistep form etc.