This should hopefully do the trick:
/**
* Append the image categories to the current image class.
*
* @see http://wordpress.stackexchange.com/a/156576/26350
*/
add_filter( 'get_image_tag_class',
function( $class, $id, $align, $size )
{
foreach( (array) get_the_category( $id ) as $cat )
{
$class .= ' category-' . $cat->slug;
}
return $class;
}
, 10, 4 );
Testing (WP 3.9.1):
If we set the image categories as (for example):
rolling-stones, steel-wheels-tour, wembley
Screenshot:

and then insert the image into the post, we get the extra classes as expected:
category-rolling-stones category-steel-wheels-tour category-wembley
Screenshot:

Related Posts:
- How to add a rel attribute to images that contains their categories?
- remove links from images using functions.php
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- Best way to programatically add “rel” attributes to page and post images
- Image rotation fails to regenerate custom sized thumbnail
- Display images that are not in the content
- How to hide image-url if no attachment?
- What are the meta fields for an attachment?
- Get Attachment Category Name
- Different image using srcset function
- Auto delete content in specific folder inside media library
- How to update an image attachment’s alt text from a custom field when saving a post?
- Open image size links in a page instead of direct image link
- Missing feature image link function
- Add image size if page template
- Set JPEG compression for specific custom image sizes
- Issue with wp_get_attachment_image() and SVG file type
- Removing default image size list in Media Box
- WP 4.4. responsive loads normal image after loading the responsive image
- How to reduce original image quality on upload?
- Set image size on media and text block with a function
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- How to Acheive the custom woocommerce category template
- Remove images from get_the_excerpt
- Assign category using custom field?
- Insert width & height attributes to all images displayed on each page
- How To Get WordPress Categories Link List?
- Changing post category from dropdown
- Manipulate Output of wp_list_something: select menu instead of li’s
- Overwrite Parent Theme add_image_size in Child Theme
- Images uploaded using media uploader are appearing upside down
- Count total number of images in post and echo results as number
- Get the category name outside of the loop in category.php
- Is it possible to change any of the HTML/URL returned from the_category()
- How do I permanently Disable Attachment Post URL
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Unset Category if other Category is unset during post transition
- Automatically wrap multiple images in div
- Understanding and altering the structure of posted images
- Load post attached images on a single page site with fancybox
- Publish/Update post is changing image links from file url to post url
- Featured Image Thumbnail Creation
- Link Attachment Image to Category
- Show Primary Category first when I display post categories
- How do I hide or remove ‘Category’ from wordpress breadcrumbs
- show first 3 thumbnails of posts in different sizes [closed]
- Getting custom image size URL in functions
- Set spesific size of featured images
- media resize/crop possibilities?
- Get category URL for current post
- Get ID of first image attached to a post
- allow only one post in specific category
- Running script based on Category
- Return category name with & Ampersand doesnt work
- Control the srcset much more (not all sizes in it each time)
- Way to store featured image width and height in two separate variables?
- srcset and custom field get_post_meta and wp_get_attachment_url
- Visual Composer creating own shortcodes with vc_map() to return simple Image
- attachment page template? only show attachments for current post?
- Access category within rss2_head hook?
- Randomizing wp_tag_cloud() in child theme
- Woocommerce image sizes missing from Appearance › Customize but not declared by theme
- Image loading function not working on archive.php template
- Add attribute only to first image of every post via functions.php
- Need to convert image url to a Base_64 data url with wordpress function..
- “All posts” in the category widget
- Using add_image_size in functions.php to get original uploaded file
- How d0 i get the number of attachments in the post
- Get slug of current category in functions.php
- Custom image sizes showing in Classic Editor only when upladed directly to post
- how can I change all wordpress media file url to custom cdn url?
- Display a list of random terms from custom taxonomy with shortcode
- How to change images url in function.php?
- WP_Query for Attachments not working as expected
- Class parameter in get_avatar args doesn’t get added to output
- Images with overlay
- how to remove a tag in the_category function
- Remove all video attachment, both files and post/postmeta from database?
- Graphic before title – Specific Category
- Printing medium sized image
- Why am I losing image quality on my site?
- Replace image attributes for lazyload plugin on image elements with specific class
- Zip all (original) images from media gallery
- No compression occurs on my jpegs after adding jpeg_quality hook to my functions.php file
- Update add_image_size
- Function the_content
- Dynamically adding Captions to images
- Full size image option removing problem
- Image width issue in IE [closed]
- How to link images of one WP site to another WP site?
- image_size with respect to aspect ratios
- Removing all Category pages with one exception
- How to resize image from import image url?
- How to crop image in WordPress with aspect ratio for any size of image
- How to add height and width dimensions automatically to archive descriptions
- How to overwrite image if it already exists – WordPress, Gravity form
- Get category of post inside save_post hook
- How Do I Prevent Featured Image Caption Displaying Above And Below Image
- Override categories with Pages (block theme)
- How to force Cover block to use the full size image resolution