views:

651

answers:

2

Hello all,

I have a joomla website with the virtuemart module.

What I have are images and thumbnails which are hosted on a other domain.

Virtuemart gives me 2 options:

1 - browse for image, a thumbnail will be automaticly created

2 - enter a URL for a image which is external hosted, this option doesn't have a resize option

The way I have overcome this problem (with help ofcourse) is to set a height="" attribute to the img tag. The only problem is that when a big image is loaded ie: 500 x 700 px, the so called thumbnail takes time to load, this is logical.

Can someone give me options how a image from a url can be "resized" with as outcome that the thumbnail takes less time to load?

Personally I was thinking about a way to decrease the image quality of the resized image which comes from a url with a code, css or anything else?

I know this has less to do with solving a code, but I know you guys know more options then I do.

A: 

You can make use of imagecopyresampled function of PHP.

Sample program (source: php.net)

<?php
// The file
$filename = 'http://valplibrary.files.wordpress.com/2009/01/5b585d_merry-christmas-blue-style.jpg';
$percent = 0.5; // percentage of resize

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 100);
?>
codaddict
can this also be done from a external image url?
Chris
sure it can be, I've added an example to the post which does that
codaddict
Great thanks for your help!
Chris
@ bzabhi, would you be so nice to take a look at my next problem, it involves the code you gave me.[http://stackoverflow.com/questions/1961031/resample-script-how-to-make-it-work-in-a-excisting-website-with-different-img-ur][1] [1]: http://stackoverflow.com/questions/1961031/resample-script-how-to-make-it-work-in-a-excisting-website-with-different-img-ur
Chris
A: 

keep in mind it wont speed up the loading time.

Grumpy