PHP 7 Script to Resize Images Using imagecopyresized() Method in Browser Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments

 

Welcome folks today in this blog post we will be resizing images using imagecopyresized() method in browser using php 7. All the full source code of the application is shown below.

 

 

 

Get Started

 

 

 

In order to get started you need to make an index.php file and copy paste the following code

See also  PHP 7 TCPDF Library Example to Generate PDF Document With Default Header & Footer in Browser Full Project For Beginners

 

 

index.php

 

 

 

<?php
// File and new size
$fname = 'extreme-snowboarding-1920x1080-winter-jump-snow-10925.jpg';


//set $percent value <1 for shrinking and $percent value >1 for expanding
$per = 0.3;

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

//Generate new size parameters
list($width, $height) = getimagesize($fname);
$new_w = $width * $per;
$new_h = $height * $per;

// Load image
$output = imagecreatetruecolor($new_w, $new_h);
$source = imagecreatefromjpeg($fname);

// Resize the source image to new size
imagecopyresized($output, $source, 0, 0, 0, 0, $new_w, $new_h, $width, $height);

//Display Output 
imagejpeg($output);
?>

Leave a Reply