i want to enlarge the images with no reducing clarity,,, and how to minimise the size(kb) of an image... also with quality..
pls help ..
Nari
i want to enlarge the images with no reducing clarity,,, and how to minimise the size(kb) of an image... also with quality..
pls help ..
Nari
Short answer: enlarging a raster (pixel) image cannot magically add true detail; you either need a larger original, convert the artwork to vector, or use a specialized upscale tool that guesses detail. rightly shows a server-side resample approach, but that alone will only interpolate pixels and can produce softness.
Practical options that work in the real world:
How to reduce KB without visible quality loss:
Quick troubleshooting checklist:
Recommended reading/tools: ImageMagick for batch processing (https://imagemagick.org) and the WebP docs for modern web formats (https://developers.google.com/speed/webp).
You can't enlarge the same image by retaining the clarity.
You have to store a different large image for enlarge image.
You can save different KBs of same image and use whenever you want.
function upload_image($name, $tname, $size, $path, $wth, $hth)
parameters are : as follows
$name - name of the uploaded image file
$tname - tem_name of the uploaded image file
$size - bite size of the imagefile
$path - where do you want to save the image
$wth - to width you want to resize
$hth - to height you want to resize
You may not need the 'getBaseName($image_name)' function, but it was in my function set.
Try to implement the code. Good luck with this.
<?php
function resizeimage($tname, $ext, $to_wth, $to_hth)
{
list($width,$height) = getimagesize($tname);
$wratio = $to_wth/$width;
$hratio = $to_hth/$height;
$ratio=($hratio < $wratio) ? $hratio : $wratio;
$new_width=round($width*$ratio);
$new_height=round($height*$ratio);
$imageResized = imagecreatetruecolor($to_wth, $to_hth);
$bg=imagecolorallocate ( $imageResized, 255, 255, 255 );
imagefill ( $imageResized, 0, 0, $bg );
switch($ext) {
case 'jpg':
$imageTmp = imagecreatefromjpeg($tname);
break;
case 'jpeg':
$imageTmp = imagecreatefromjpeg($tname);
break;
case 'png':
$imageTmp = imagecreatefrompng($tname);
break;
case 'gif':
$imageTmp = imagecreatefromgif($tname);
break;
default:
echo("Error Invalid Image Type");
die;
break;
}
$x_mid = $new_width/2;
$y_mid = $new_height/2;
//imagecopyresized($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($imageResized, $imageTmp, (($to_wth-$new_width)/2), (($to_hth-$new_height)/2), 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}
function upload_image($name, $tname, $size, $path, $wth, $hth)
{
$oext=getExtention($name);
$ext=strtolower($oext);
$base_name=getBaseName($name);
if($ext=="jpg" || $ext=="jpeg" || $ext=="png" || $ext=="gif")
{
if($size< 1024*1024*10)
{
$tname = resizeimage($tname, $ext, $wth, $hth);
if(!file_exists($path."".$name))
{
imagejpeg($tname,$path."".$name);
//move_uploaded_file($tname,$path."".$name);
return 1;
}
return 0;
}
else
{
echo "Image size excedded.<br />File size should be less than 10Mb<br />";
return 0;
}
}
else
{
echo "Invalid file extention '.$oext'<br />";
return 0;
}
return 0;
}
function getExtention($image_name){
return substr($image_name,strrpos($image_name,'.')+1);
}
function getBaseName($image_name){
return substr($image_name,0,strrpos($image_name,'.'));
}
?> We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.