How to resize image from url and reduce image size

I have a joomla site with virtuemart module.

I have images and thumbnails hosted in another domain.

Virtuemart gives me 2 options:

1 - view image, sketch will be automatically created

2 - enter the URL for external placement, this parameter does not have the option to resize

As I overcame this problem (using context), I need to set the height = "" attribute for the img tag. The only problem is that when loading a large image, that is, 500 x 700 pixels, the so-called thumbnail takes time to load, this is logical.

Can someone give me options on how the image from the URL can be “modified” as the result reduces the time it takes to download the sketch?

Personally, I was thinking of a way to reduce the image quality of a modified image that comes from a url with code, css, or something else?

I know this has less to do with code solution, but I know that you guys know more options than me.

+4
source share
1 answer

You can use the imagecopyresampled PHP function.

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); ?> 
+11
source

All Articles