2
votes

When I upload images wordpress saves four files onto the server (as defined in settings->media):

1 -> thumbnailsize (150x150)
2 -> Medium size (1024x768)
3 -> Large size (1920x1080)
4 -> Original size (---x---)

I always need the large size image, but when I upload an image with a size of 1620x1080 , Wordpress will name the image some-image-1620x1080.jpg what I don't want.

Can I change in any way the imagename from some-image-1920x1080.jpg to some-image-large.jpg?

2

2 Answers

1
votes

You'll have to create a function in your functions.php file, which will handle the file upload and will be hooked at filter wp_handle_upload_prefilter:

add_filter('wp_handle_upload_prefilter', 'wp_rename_large_images', 1, 1);
//Check to see if function name is unique
if (!function_exists("wp_rename_large_images")) {
function wp_rename_large_images( $file ){
   //Get image size 
   $img = getimagesize($file['tmp_name']);
   //Image dimensions
   $width = $img[0];
   $height = $img[1];
   //Check to see if image is large enough to change the file name
   if ($width > 1200 || $height > 1080) {
     //Modify the file name WITH an extension
     $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
     //Build the new file name (remove the old extension - last 3 characters from the file name, i.e. jpg, gif, png, bmp, etc.)
     $file['name'] = substr($file['name'], -3) . '-large'. $ext;
   }
    return $file;
}
}

Read the documentation here.

0
votes

I still haven't found a particular solution for this problem, and a few people claim that you cannot change the name of the uploaded files, only add something to it. What I've used now is Gallery Theme plugin by Maxon in order to get my thumbnail and large-images in two seperate data-paths, what fixed my entire problem. The plugin is massively lightweight and does the job perfectly for galleries.

The plugin can be found here: http://wordpress.org/plugins/gallery-theme/