share this
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
<?php
function convert_image($sname)
{
header(‘Content-type: image/jpeg,image/gif,image/png’);
//image size
list($width, $height) = getimagesize($sname);
$wid=450;
$hei=450;
$thumb = imagecreatetruecolor($wid,$hei);
//image type
$type=exif_imagetype($sname);
//check image type
switch($type)
{
case 2:
$source = imagecreatefromjpeg($sname);
break;
case 3:
$source = imagecreatefrompng($sname);
break;
case 1:
$source = imagecreatefromgif($sname);
break;
}
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0,$wid,$hei, $width, $height);
// source filename
$file = basename($sname);
//destiantion file path
$path=”/opt/lampp/htdocs/images/”;
$dname=$path.$wid.”x”.$hei.”_”.$file;
//display on browser
imagejpeg($thumb);
//store into file path
imagejpeg($thumb,$dname);
}
?>
this is example for image resizing in 200 width and 262 height…
you can also change the width and height you needed by change value of $wid and $hei..
it will help you in resize to what ever you want…
pass the source file name with their path to convert_image function
$sname–>Source file
$path–>Destination path..
it will generate destination file name automatically using source name..
for example if your file in htdocs specify $sname as /opt/lampp/htdocs/file_name.
$path is the place where you want to store.
GO TO THE TERMINAL
type “sudo chmod -R 777 file name”
is necessary……
Leave a Reply