Dynamic Image Resizer
Updating old images for use with Dynamic Image Resizer (1 post)

  1. sliceofpie
    Posted 4 years ago #

    Below is some code I've used to update old images to work with this plugin. This is only necessary if you've added or changed image sizes after some images were originally uploaded. It re-writes the metadata for image attachments, thus activating the plugin's hook in wp_update_attachment_metadata that does all the magic.

    // Necessary if you've added or changed image sizes
    // May require you pump up your memory_limit & max_execution_time in php.ini if you have lots of image files...
    function makeimagesresizable() {
    	global $dynimg_image_sizes, $_wp_additional_image_sizes;
    	$dynimg_image_sizes = $_wp_additional_image_sizes;	// I think its necessary to fill this global used in DynImgResize? Maybe not
    	require ( ABSPATH . 'wp-admin/includes/image.php' );	// Neccesary for wp_generate_metadata (not always)	
    	$images = get_children( 'post_type=attachment&post_mime_type=image&numberposts=-1&order=DESC&orderby=menu_order&post_parent=' ); // All images
    	foreach($images as $i){
    		$data = wp_generate_attachment_metadata($i->ID,$i->guid);
    		wp_update_attachment_metadata($i->ID,$data);	// DynImgResize has a hook in this function that adds the data for not-yet-existant image files
    		echo $i->ID." : ".$i->guid."<br/>";

    (^ This can probably be improved... Just offering it up if it might help someone out in the future. Amazingly useful plugin.)


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Dynamic Image Resizer
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

  • RSS feed for this topic
  • Started 4 years ago by sliceofpie
  • This topic is not a support question
  • WordPress version: 3.4.1