I'm attempting to add a function to my site where users can set their profile picture as an image from an external url, instead of saving it to their pc, then uploading it to my server.
This is what I've come up with so far:
$filename = $inputs['image_url'];
if(getimagesize($filename)){
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = 100;
$new_height = 100;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
//a check needs to be done here $image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$filename = "profile_pictures/". md5( uniqid(rand(),true) ).".jpg";
imagejpeg($image_p,$filename,100);
}else{
echo 'This is not an image';
}
The code can download .jpg images fine, but I want to support other filetypes too.
I need to somehow check the file type of the image so I can save other images with different filetypes...
if($extension=="jpg" || $extension=="jpeg"){
$image = imagecreatefromjpeg($filename);
}else if($extension=="png"){
image = imagecreatefrompng($filename);
}else{
$image = imagecreatefromgif($filename);
}
Does anyone know of a function that would allow me to do this?
Thanks in advance for any replies.