You’ve added images everywhere before in sites like facebook and MSN. The procedure is fairly straightforward to open an image, resize the image, rewite the image and save the new image. Below is a siomple tutorial with a form showing how to add a resized image into a form.
// if user chosed properly then scale down the image according to user preferences
if(isset($_REQUEST[‘max_img_width’]) and $_REQUEST[‘max_img_width’]!=” and $_REQUEST[‘max_img_width’]<=$max_image_width){
$max_image_width = $_REQUEST[‘max_img_width’];
}
if(isset($_REQUEST[‘max_img_height’]) and $_REQUEST[‘max_img_height’]!=” and $_REQUEST[‘max_img_height’]<=$max_image_height){
$max_image_height = $_REQUEST[‘max_img_height’];
}
// JPEGs
if($_FILES[“img_upload”][“type”] == “image/jpeg” || $_FILES[“img_upload”][“type”] == “image/pjpeg”){
$image_source = imagecreatefromjpeg($_FILES[“img_upload”][“tmp_name”]);
}
// GIFs
if($_FILES[“img_upload”][“type”] == “image/gif”){
$image_source = imagecreatefromgif($_FILES[“img_upload”][“tmp_name”]);
}
if($_FILES[“img_upload”][“type”] == “image/x-png”){
$image_source = imagecreatefrompng($_FILES[“img_upload”][“tmp_name”]);
}
$remote_file = “my_uploaded_images/”.$_FILES[“img_upload”][“name”];
imagejpeg($image_source,$remote_file,100);
chmod($remote_file,0644);
// get the dimensions in width and height of orig image
list($image_width, $image_height) = getimagesize($remote_file);
if($image_width>$max_image_width || $image_height >$max_image_height){
$proportions = $image_width/$image_height;
if($image_width>$image_height){
$new_width = $max_image_width;
$new_height = round($max_image_width/$proportions);
}
else{
$new_height = $max_image_height;
$new_width = round($max_image_height*$proportions);
}
$new_image = imagecreatetruecolor($new_width , $new_height);
$image_source = imagecreatefromjpeg($remote_file);
imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image,$remote_file,100);
imagedestroy($new_image);
}
imagedestroy($image_source);
}
else{
}
?>
HTML CODE HERE
<form name=”form1″ method=”post” action=”<?php echo $_SERVER[‘SELF’];?>” enctype=”multipart/form-data”>
Maximum 1MB. Accepted Formats: jpg, gif and png:<br />
<input name=”img_upload” type=”file” id=”img_upload” size=”40″ />
<br />
<br />
<br />
<input name=”max_img_width” type=”hidden” id=”max_img_width” value=”130″ size=”4″>
<input name=”max_img_height” type=”hidden” id=”max_img_height” value=”54″ size=”4″>
<tr>
<td >First Name</td>
<td><input name=”FirstName” value=”” type=”text” id=”FirstName”></td>
</tr>
<tr>
<td>Last Name </td>
<td ><input name=”LastName” value=”” type=”text” id=”LastName”></td>
</tr>
<p><input type=”submit” class=”form_submit_button” onclick=”display_alert()” name=”Submit” value=”Submit”>
</p>
</form>
You may want to add the image name to a database table for other purposes; such as a user’s profile picture. Below, shows how this can be done.
You can add this above the form!
© 2018 ALL Rights Reserved | Sitemap
Vancouver | North Vancouver | Burnaby | Richmond | Coquitlam | Port Coquitlam | Surrey | Langley | Maple Ridge | Mission | Abbotsford | Kamloops | Kelowna | Victoria | Squamish | Whistler | Pemberton