Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#19679 closed enhancement (wontfix)

Quicker image compression

Reported by: mariusmandal's profile mariusmandal Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3
Component: Media Keywords: has-patch close
Focuses: Cc:

Description

When uploading a 8MB photo, WP used 12 seconds to compress the image to 4 sizes. After a quick mod, it uses 4 seconds to do the same job, without any noticable image quality loss (even though there is a small theoretical one)

Shortly put:
Sort sizes by area from large to small, and always create <this size> from the last image.
(the image size sorting might be done better, without me knowing how to at the moment..)

Why not do it like this? :)

My modifications to wp-admin/includes/image.php, replacing line 122-128 :

foreach($sizes as $size => $info) {
	$newsizes[ $info['width']*$info['height'] ] = $info;
	$sizename[ $info['width']*$info['height'] ] = $size;
}
krsort($newsizes);
foreach($newsizes as $res => $info)
	$sizes[$sizename[$res]] = $info;

$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );

foreach ($sizes as $size => $size_data ) {
	$resized = image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
	if ( $resized ) {
		$metadata['sizes'][$size] = $resized;
		$file = str_replace(substr($file, strrpos($file,'.')),
				'-'.$resized['width'].'x'.$resized['height'].substr($file, strrpos($file,'.')),
				$file);
	}
}

Change History (5)

#1 follow-up: @scribu
13 years ago

  • Keywords close added

I'm not so sure the image quality would always be the same.

But the real deal breaker is that intermediate image sizes aren't always sortable, i.e. you can have a 400x600 size and a 600x400 size. Not to mention cropping.

#2 in reply to: ↑ 1 @mariusmandal
13 years ago

Replying to scribu:

I'm not so sure the image quality would always be the same.

But the real deal breaker is that intermediate image sizes aren't always sortable, i.e. you can have a 400x600 size and a 600x400 size. Not to mention cropping.

Of course! Bit too quick here.. I was thinking of crop earlier, but forgot it during the process of coding..

BWhat about using the large one, instead of the original one if the resolution is quite different? A 8mpx image is far from a 2mpx in process time.. :)

My multisite users often complain about long image processing time, but maybe this is unique for my site?

#3 @scribu
13 years ago

Have you tried using ImageMagick instead of GD?

http://wordpress.org/extend/plugins/imagemagick-engine/

#4 @nacin
13 years ago

I would think that generating an image off a generated image would result in lower quality. The lossiness would only multiply.

Merging in the IM plugin is definitely something we'd like to do, though.

#5 @scribu
13 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Yeah, there's already a ticket for that: #6821

If this method works for you, mariusmandal, you should be able to implement it as a plugin.

Note: See TracTickets for help on using tickets.