• Hi I’m working on a locally installed (WAMP) website. I’m using this code in the functions file to limit the largest images to the dimensions set in Settings>Media:

    add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
    	/* limits image size to large setting */
    function replace_uploaded_image($image_data) {
    
        if (!isset($image_data['sizes']['large'])) return $image_data;
    
        // paths to the uploaded image and the large image
        $upload_dir = wp_upload_dir();
        $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
        $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file'];
    
        // delete the uploaded image
        unlink($uploaded_image_location);
    
        // rename the large image
        rename($large_image_location,$uploaded_image_location);
    
        // update image metadata and return them
        $image_data['width'] = $image_data['sizes']['large']['width'];
        $image_data['height'] = $image_data['sizes']['large']['height'];
        unset($image_data['sizes']['large']);
    
        return $image_data;
    }

    This works great on several other of my sites. I don’t need the full-size image on most sites so this is awesome to save the time of resizing before uploading. However, I just put it on my locally installed site that I’m working on, and get the following error:

    Warning: rename(C:\Users\Tevya\Work\wamp\www\acsr/wp-content/uploads/2010/08/American-Construction-Supply-119-800x492.jpg,C:\Users\Tevya\Work\wamp\www\acsr/wp-content/uploads/2009/11/American-Construction-Supply-119.jpg) [function.rename]: No error in C:\Users\Tevya\Work\wamp\www\acsr\wp-content\themes\centivio3\functions.php on line 17
    414

    When I try to upload a new image. It seems to actually work, however, it doesn’t properly rename the large file to the original file name, so if you use the link to file button, or try to insert the full-size image, there’s nothing there.

    Can anyone tell me if this is typical of WAMP and I just need to get this site on the host and it will work then? Or if there’s something I can do to make it work locally? Or is it perhaps a conflict with the theme? Any help would be greatly appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Tevya

    (@thefiddler)

    Update: it seems to work fine now that I’ve uploaded the site to the host and moved the database there too. Must be an issue with WAMP or something local.

    Hi

    I’ve got the same problem. I’m not certain what is causing it but the issue is the paths do not match.

    In your post above

    /uploads/2010/08/American-Construction-Supply
    /uploads/2009/11/American-Construction-Supply

    Very odd, I think it is something to do with the original post date and the new image URL

    Have you resolved it at all?

    Lee

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Auto image resize function not working on local install?’ is closed to new replies.