Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Generate images to be associated for tag and category?

Ignoring our off-topic request for a plugin, the good news is: yes, this is possible. On the other hand, it is quite some work, so I will give just an outline here.

WordPress does have built-in image manipulation. The default one is Image Magick. WordPress’ image editor class, however, only offers a subset of what Image Magick is actually capable of. This means that you will have to pierce through the class and use the PHP commands directly to do what you want.

First you will have to register an image size

add_action( 'init', 'wpse358037_register_collage_size' ); 
function wpse358037_register_collage_size() {
  add_image_size( 'collage', 1024, 512, true ); 
  }

Second, when a tag is created you want to set a featured image for it, composed from one or more featured images of posts with that tag. There are several ways to do this, but the handiest may be hooking into the set_object_terms action. This fires at the end of wp_set_object_terms, a function that is executed whenever a post taxonomy is created or updated. Assuming that you only want to update the collage image when a new post/picture has been added, this is the perfect hook to create/update the collage without putting a burden on your server. You create the collage image and attach it as metadata to the tag. Pseudocode:

add_action( 'set_object_terms', 'wpse358037_register_collage_size', 10, 6 );
function wpse358037_register_collage_size ($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) {
  if (... some sort of condition to match only post tags ...) {
    // if there are multiple tags, you may have to loop throug them
    foreach ($tags as $tag) {
      $images_to_be_used = ... depending on tag and you criteria make array of images
      $collage_image_path = wpse358037_collage_image ($tag, $images_to_be_used);
      // save the path to the resulting image as metadata to the tag
      add_term_meta ($tag_ID, 'collage-image', $collage_image_path, false) ;
      }
    }
  }

Finally you’ll have to do the actual image action for which Image Magick even has a native function called mosaic:

 function wpse358037_collage_image ($tag, $images_to_be_used) {
   // loop through all $images_to_be_used doing this
     $collage_image[i] = new Imagick( $path_to_image);
   // now you have an array of images ready to be handled by Image Magick
     .. do your mosaic magic and save the result in $collage_image_final_result
   // all that is left now is saving the image and return the path so it can be saved as metadata
   $path = .. wherever you want to save it (upload_dir + name + '.jpg')
   $collage_image_final_result->writeImage ($path);
   return $path;
   }

As you can see, there’s still quite a lot of development work to be done, but hopefully this outline will help you get what you want.

Related Posts:

  1. Is there a hook which fires after all thumbnails are generated?
  2. Remove title attribute from images
  3. Force default OG:Image – Yoast SEO [closed]
  4. How to Display Image Caption but Not Alt Text
  5. Filter to remove image dimension attributes?
  6. Stop wordpress from hardcoding img width and height attributes
  7. Programmatically get images by URL and save in uploads folder
  8. Set default image link target in Gutenberg image block
  9. How to automatically add rounded corners to thumbnails?
  10. WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
  11. Download an image from a webpage to the default uploads folder
  12. How to change image type for specific size?
  13. is it possible to replace the use of gd_lib with imagick or ImageMagick?
  14. Separate Media Library for each user
  15. Featured image shortcode
  16. How to find attachment by it’s name?
  17. Change WordPress image URLs via filter
  18. get_the_post_thumbnail_url with an unregistered size
  19. Cropped featured image replaces original image in gallery
  20. Image Scaling using get_the_post_thumbnail issue in WordPress
  21. Remove P tags from images
  22. Any easy way to automatically set the first inline image in a post as the thumbnail?
  23. Insert an image into a post by API
  24. Saving the pre-sanitized filename of an attachment as the Title or Caption
  25. How to create thumbnails with a fixed width, so all of them will have the same width?
  26. How to limit number of images being printer out in “Set Featured Image” pop up?
  27. Black and White thumbnails
  28. Programatically creating image attachments from local URLs and setting featured image
  29. How can I add the “Use as featured image” to a custom metabox?
  30. set_post_thumbnail_size not cropping featured images, but reducing proportionally
  31. How to grab first image attached to post and display in RSS feed?
  32. Double thumbnails?
  33. Alter image output in content
  34. No srcset for hard-cropped thumbnails
  35. Is it possible to prevent users from uploading small images?
  36. Can’t Display Featured Image in RSS Feed
  37. Displaying a featured image (only img url) as the img src?
  38. Display info from custom fields in all images’ HTML
  39. How to output placeholder image if no featured image set?
  40. Featured Images on Front Page
  41. Download button for Featured Image in every post – automatically
  42. Wrap all post images inside a div element
  43. alt, title tags not showing
  44. Removing Title Tag from Thumbnails
  45. Show prev and next post links for parent post of current image in attachment page?
  46. Setup A Default Featured Image
  47. When displaying the featured image, is has_post_thumbnail() necessary?
  48. Find posts without featured image? [duplicate]
  49. How do I add a featured image to a single post page?
  50. Add a featured image in my theme?
  51. Regenerate missing _wp_attachment_metadata
  52. Disable wordpress image sizes generation
  53. Get original image from thumbnail URL
  54. Featured Image .svg height and width 1px only
  55. How to check if user is uploading/setting an image as a featured image?
  56. Getting alt text of featured image
  57. Images are randomly deleted from server
  58. Frontend Post – Allow Only Image File Upload
  59. attach unattached featured images to respective posts
  60. Images not working using Featured post
  61. Add instructions to featured image
  62. WordPress reduces the full size image and uses it as the original
  63. How do I get more image editing options in the admin?
  64. Thumbnails are bigger in size than the original image
  65. Remove image classes from post thumbnail output
  66. Lazyload post thumbnails
  67. Add “data-” attribute to image links
  68. Retrieving an alt tag from a custom field
  69. Exclude featured image from gallery in wp-admin
  70. Special purpose photos with each post
  71. Get thumbnail url of custom meta image?
  72. SVG Featured image not shown in twitter
  73. Featured images not displaying at full resolution
  74. Woocommerce featured image of page – not product
  75. Set Post Image Using Shortcode
  76. Print specific image size in galley loop
  77. WordPress crops images differently on retina screens?
  78. Can’t seem to attach uploaded image to post and set it as thumbnail
  79. Big Image on Featured Post, Normal on Single Post
  80. offload media to external services [closed]
  81. Store Snapshot created via wordpress to use with lightbox
  82. Dynamic tagged image galleries
  83. How to stop thumbnail generation from some images and different size thumbnail generate
  84. Update old Post image metadata to ‘thumbnail’ wp_attached_file
  85. How to stop wordpress always displaying full-res images
  86. How to change image atributes right before an image to be saved?
  87. How can I add a “data-pin-nopin” the featured image html?
  88. How to add custom classes to figure element only if image has caption?
  89. How to filter the image embed code based on link type
  90. WP keeps looking up post thumbnail on https even though wp-config says http
  91. Images stopped loadding after adding SSl
  92. WordPress PNG compression issue
  93. How to replace images?
  94. Fixing image names for a site being restored
  95. Setup Featured image on all posts from thesis thesis_post_image custom field?
  96. Add custom text in the media library image meta area
  97. Export xml use/import images from theme directory
  98. Custom Loop, Match Category with Page: How to display post featured image?
  99. How do I get my main image to stretch the full length of the screen?
  100. Display an icon with get_post_meta?
Categories images Tags hooks, images, post-meta, post-thumbnails, tags
Strange behaviour of is_user_logged_in() and get_current_user_id()
How to position user meta data field

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress