Can someone show me how to not have watermark with this function? all i want it to do is just resize image without any watermark.
Issue i am facing with the codes right now is say 2 out 100 images being uploaded by users the image seems to be completely black
$image_path = "../css/images/logo.png";
function watermark_image_post($oldimage_name, $new_image_name){
global $image_path;
list($owidth,$oheight) = getimagesize($oldimage_name);
$width = 720; $height = 450;
$im = imagecreatetruecolor($width, $height);
$img_src = imagecreatefromjpeg($oldimage_name);
imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
$watermark = imagecreatefrompng($image_path);
list($w_width, $w_height) = getimagesize($image_path);
$pos_x = $width - $w_width;
$pos_y = $height - $w_height;
imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height);
imagejpeg($im, $new_image_name, 90);
imagedestroy($im);
unlink($oldimage_name);
return true;
}
the html
<div class="row form-group">
<img id="output" class="imgoutput wdt"/>
<div class="col-md-12">
<label for="activities">Please attach your photo (250x250)</label>
<input type="file" name="file" id="file" accept=".jpg, .jpeg" onChange="loadFile(event)" class="form-control" />
</div>
</div>
This is how i error handle
if($_FILES['file']['size'] == '0'){
$error[] = 'Please attach your photo.';
}elseif($_FILES["file"]["size"] > 2097152){
$error[] = 'Selected image size is too large, upload under 2mb.';
}elseif(!in_array($_FILES["file"]["type"], array("image/jpg", "image/jpeg"))){
$error[] = 'We accept only (JPG / JPEG) image file type.';
}
here is the part used in form, anyway to resize directly with the below code?
if($_FILES['file']['name']!='')
{
$tmp_name = $_FILES["file"]["tmp_name"];
$namefile = $_FILES["file"]["name"];
$cname = str_replace(' ', '-', $candidate_name);
$ext = end(explode(".", $namefile));
$fileUpload = move_uploaded_file($tmp_name,"uploads/images/".$image_name);
$image_name= $cname.'-'.time().".".$ext;
watermark_image_post($tmp_name,"uploads/images/".$image_name);
$img = ''.$image_name.'';
}
Thanks alot