how to resize image from url and make the size of the image smaller

后端 未结 1 1807
后悔当初
后悔当初 2020-12-18 08:33

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条回答
  • 2020-12-18 08:39

    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);
    ?>
    
    0 讨论(0)
提交回复
热议问题