I have the following code to upload images to my site, but the uploaded images look big and takes time to load in site, I want to make them smaller in size and also I want to add watermark from my own,
I want images to be shown like 1080X1080 but Good Quality, I tried to make the limited upload size smaller, but some users don't know how to resize photos!
$total = count($_FILES['document']['name']);
if($total > 0 ) {
$total = count($_FILES['document']['name']);
if($total<=4)
{
for( $i=0 ; $i < $total ; $i++ ) {
$canUpload = canUpload($_FILES['document'],$i);
if ($canUpload === true){
if (!is_dir($uploadDir)){
umask(0);
mkdir($uploadDir, 0775);
}
$newfile = time().$_FILES['document']['name'][$i];
if($i==0)
$filename = $newfile;
if($i==0)
$filename2 = $newfile;
else
$filename2=$filename2.",".$newfile;
if (file_exists($uploadDir. '/' .$newfile)){
$documentError = 'File already exsist';
} else {
move_uploaded_file($_FILES['document']['tmp_name'][$i], $uploadDir. '/' .$newfile);
}
} else{
$documentError = $canUpload;
}
}
}
else
{
$documentError ="4 images allowed Only!";
}
You need to use either PHP's ImageMagick or GD functions to work with images.
With GD, for example, it's as simple as...
And you could call this function, like so...
From personal experience, GD's image resampling does dramatically reduce file size too, especially when resampling raw digital camera images.
and for watermark
A good example in the PHP manual: