• Resolved Tevya

    (@thefiddler)


    I’m using this code in my functions.php file to resize images to the “large” size specified in Settings>Media when the user uploads the image:

    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;
    }

    It works great most of the time. However, if the image is too large, it gives this error:
    Fatal error: Out of memory (allocated 67371008) (tried to allocate 16000 bytes) in /home/folderhere/public_html/wp-includes/media.php on line 254

    I assume that not enough memory is available to process the resize in these instances. Can somebody point me to what settings on my hosting, would need to change in order to give it enough memory, so it would work correctly?

Viewing 1 replies (of 1 total)
  • Thread Starter Tevya

    (@thefiddler)

    Nevermind, I posted too quickly, I found other threads addressing this. Looks like Hostgator’s hosting sucks. Can’t adjust anything above 64M under any conditions. And their solution is always the same: “pay us more money by upgrading to a VPS.”

Viewing 1 replies (of 1 total)
  • The topic ‘Fatal error when trying to resize images?’ is closed to new replies.