Just if resized image exist
Posted: 2014-07-14T04:36:07-07:00
Hi everybody,
I have a question.
I implemented a gallery using ImageMagick to WordPress, but seems slow. I tried to optimize but nothing.
Is there any chance to run the resize process just that time if the resized image is doesn't exist?
My current code is:
Thanks,
levipadre
I have a question.
I implemented a gallery using ImageMagick to WordPress, but seems slow. I tried to optimize but nothing.
Is there any chance to run the resize process just that time if the resized image is doesn't exist?
My current code is:
Code: Select all
<?php
$imgdata = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
$imgurl = $imgdata[0]; // the url of the thumbnail picture
$imgwidth = $imgdata[1]; // thumbnail's width
$imgheight = $imgdata[2]; // thumbnail's height
if($imgurl != '') {
$parsed_url = parse_url($imgurl);
$path = $_SERVER['DOCUMENT_ROOT'] . $parsed_url['path'];
$img = wp_get_image_editor( $path );
if ( ! is_wp_error( $img ) ) {
$old_size = $img->get_size();
$img->resize( 140, 140, true );
$suffix = $img->get_suffix();
$filename = $img->generate_filename( 'resized-to-' . $suffix , $parsed_url['path'] , NULL );
if ($resize !== FALSE) {
$new_size = $img->get_size();
$img->set_quality(80);
$saved = $img->save($filename,NULL);
}
}
$newpath = str_replace('C:/wamp/www/', '/', $filename);
?>
<img src="<?php echo $newpath; ?>" width="<?php echo $saved['width']; ?>" height="<?php echo $saved['height']; ?>" alt="" />
<?php } ?>
levipadre