Hello,
I have code that resizes the images
images_resize.php
There are two image upload options in the member profile editing area
1.Brand logo upload option
<input type="file" name="brand_logo">
2.Profile picture upload option
<input type="file" name="profile_picture">
################################################################################
if($_FILES['brand_logo']['size'] > 0){
//For Brand Logo Images
$width = "260";
$height = "113";
$home_directory = "images/";
$subdirectory = "logo_pictures/";
include(images_resize.php);
// Output variable
$brand_logo_resize;
}
################################################################################
if($_FILES['profile_picture']['size'] > 0){
//For Profile Pictures
$width = "80";
$height = "80";
$home_directory = "images/";
$subdirectory = "profile_pictures/";
include(images_resize.php);
// Output variable
$profile_picture_resize;
}
Image processing code is below
if (isset($_FILES["fileToUpload"]) && $_FILES["fileToUpload"]["size"] > 0) {
$target_dir = $home_directory.$subdirectory;
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
//echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
############### Image resizing ################################################
function boyutla($resim, $tresim, $max_en, $max_boy){
$arraylar = explode('.',$resim);
$sonuc = $arraylar[(count($arraylar) -1)];
$sonuc = trim($sonuc);
$sonuc = strtolower($sonuc);
switch ($sonuc){
case "jpeg": $islem=imagecreatefromjpeg($resim); break;
case "JPEG": $islem=imagecreatefromjpeg($resim); break;
case "jpg": $islem=imagecreatefromjpeg($resim); break;
case "gif": $islem=imagecreatefromgif($resim); break;
case "png": $islem=imagecreatefrompng($resim); break;
case "JPG": $islem=imagecreatefromjpeg($resim); break;
case "GIF": $islem=imagecreatefromgif($resim); break;
case "PNG": $islem=imagecreatefrompng($resim); break;
}
$boyut = getimagesize($resim);
$en = $boyut[0];
$boy = $boyut[1];
$x_oran = $max_en / $en;
$y_oran = $max_boy / $boy;
if (($en <= $max_en) and ($boy <= $max_boy)){
$son_en = $en;
$son_boy = $boy;
}
else if (($x_oran * $boy) < $max_boy){
$son_en = $max_en;
$son_boy = ceil($x_oran * $boy);
}
else {
$son_en = ceil($y_oran * $en);
$son_boy = $max_boy;
}
$yeni = ImageCreateTrueColor($son_en,$son_boy);
imagealphablending($yeni, false);
imagesavealpha($yeni, true);
$transparent = imagecolorallocatealpha($yeni, $son_en, $son_boy, $en, $boy);
imagefilledrectangle($yeni, 0, 0, $son_en, $son_boy, $transparent);
imagecopyresampled($yeni,$islem,0,0,0,0,$son_en,$son_boy,$en,$boy);
switch ($sonuc){
case "jpeg": imagejpeg($yeni,$tresim); break;
case "JPEG": imagejpeg($yeni,$tresim); break;
case "jpg": imagejpeg($yeni,$tresim); break;
case "gif": imagegif($yeni,$tresim); break;
case "png": imagepng($yeni,$tresim); break;
case "JPG": imagejpeg($yeni,$tresim); break;
case "GIF": imagegif($yeni,$tresim); break;
case "PNG": imagepng($yeni,$tresim); break;
}
return $resim;
}
############### Image resizing ################################################
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" &&
$imageFileType != "png" &&
$imageFileType != "jpeg"&&
$imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
$temp = explode(".", $_FILES["fileToUpload"]["name"]);
$newfilename = round(microtime(true)) . '.' . end($temp);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir . $newfilename)) {
boyutla($target_dir . $newfilename, $target_dir.$newfilename, $width, $height);
$output_variable = $target_dir.$newfilename;
echo "<br />The file ". $newfilename. " has been uploaded.";
} else {
echo "<br />Sorry, there was an error uploading your file.";
}
}
echo "<br />Output image name: ".$output_variable;
} // if ($_FILES["fileToUpload"]["size"] > 0) {
I want to resize when either or both are loaded at the same time
However, it doesn’t resize when both are installed at the same time
How do I do this?