Jump to content

Resize an image multiple times?


radar

Recommended Posts

Greetings.. 

 

I have an ajax application i'm creating, that allows uploading images 1 at a time.  That part works, and it works well.  What I need to know now, is how would I go about converting the existing code I have, to change the sizing of it twice as well as renaming the images to something more website friendly.

 

here is the code that i currently have, im sure this is easy but as i can't find any workable code on the google, i am lost as to how to modify it.  so any help is appreciated.

 

<script language="JavaScript" type="text/javascript">
if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(window.parent.document.form1.filefieldname.value)) {
	window.parent.document.form1.filefieldname.value = "";
} else {
<?php
function rrmdir($dir) { 
	if (is_dir($dir)) { 
     		$objects = scandir($dir); 
     	foreach ($objects as $object) { 
       		if ($object != "." && $object != "..") { 
         		if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); 
		} 
     	}	 
     reset($objects); 
     rmdir($dir); 
   		} 
	} 

$folder = isset($_POST['folder']) ? $_POST['folder'] : '';
if($folder == '') {
	$rand = rand(5, 1000000);
	$folder = 'temp'.$rand;
	?>
	window.parent.document.form1.folder.value = "<?php echo $folder; ?>";
	<?php
}
if(!is_dir("../uploads/".$folder)) {
	mkdir('../uploads/'.$folder);
} else {
	$rand = rand(5, 100000);
	$folder = $folder.''.$rand;
	mkdir('../uploads/'.$folder);
}
$image_name = $_FILES["filefieldname"]["name"];
$newname = "../uploads/".$folder."/".$image_name;
move_uploaded_file($_FILES["filefieldname"]["tmp_name"], $newname);
?>
var parDoc = window.parent.document;
var A = window.parent.document.form1.upload_cnt.value;
A = Number(A);
B = 1;
var cnt = A + B;
if(cnt == '8') {
window.parent.document.form1.filefieldname.disabled=true;
}
parDoc.getElementById('upload_cnt').value = cnt;
parDoc.getElementById('files_list').innerHTML += '<br><a href="../uploads/<?php echo $folder.'/'.$_FILES['filefieldname']['name'] ?>"><?php echo $_FILES['filefieldname']['name'] 		
?></a>';
window.parent.document.form1.filefieldname.value="";
}
</script>

Link to comment
Share on other sites

Just checking in, anyone know how to do this today?  I posted the entire code, though really the only part that will matter is:

 

$image_name = $_FILES["filefieldname"]["name"];	
$newname = "../uploads/".$folder."/".$image_name;	
move_uploaded_file($_FILES["filefieldname"]["tmp_name"], $newname);

 

how to change that so that it changes the width to a certain number, and will auto adjust the height to the neighboring height ('constrain proportions').  I've never had to do it, don't know how.  and yeah.  If i can get the code for doing it one time, i should be able to theoretically copy the same code to do it a 2nd time?

Link to comment
Share on other sites

Okay so based on that code, i would change mine effectively to something like...

 

$prod_img = "../uploads/".$folder."/".$image_name;

$srcimg = ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image'); // does this work for .bmp, .gif, .jpg, .png as well? because i'm allowing the use of all of those through this script.

$width = '432';
$sizes = getimagesize($_FILES["filefieldname"]);
$aspect_ratio = $sizes[1]/$sizes[0];

$new_height = abs($width/$aspect_ratio);

createImage($width, $new_height, $srcimg, $prod_img_thumb[$cur_img]);

Link to comment
Share on other sites

I dont know i havent run it...  im actually working on a different part of the site atm..  this part is just an afterthought of the uploading feature in the administration panel.

 

so figured i would figure out how to do it, and save that info to add it in next week.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.