[1]

dartuha
Guest
December 2nd, 2008 at 1:39 am

Great plugin, Mark! There is control of image size but how to control the dimensions of uploaded image?

Permalink | Quote

[2]

Mark Cunningham
Guest
December 2nd, 2008 at 11:27 am

Do you mean, how to limit the dimensions of the image uploaded or modify it after uploading?

Permalink | Quote

[3]

dartuha
Guest
December 2nd, 2008 at 7:55 pm

Both. To limit dimensions is simpler? But to resize after uploading if profi?

Permalink | Quote

[4]

Mark Cunningham
Guest
December 3rd, 2008 at 10:15 am

I don’t know if either option is simipler. Certainly it’s not possible to limit the dimensions of the image before upload, but you can reject it once the file has been uploaded which is an utter pain if you’re on a slow connection uploading a large file.

I was depending on Wordpress to handle post formatting of images and files via their attachment mechanism. Currently there is no option to resize images apon upload, but it does generate three “sizes” – thumbnail, medium and original. To force the original to be a specific size requires additional code. I don’t know if I’ll get around to in the near future as I’m considering creating a new upload files widget.

Permalink | Quote

[5]

Vin
Guest
February 8th, 2009 at 11:47 pm

Yes, awesome plugin. So, how do I automatically resize the image after it has bee uploaded?

Permalink | Quote

[6]

Mark Cunningham
Guest
February 17th, 2009 at 10:05 am

Probably using a command tool like imagemagick in the “Command” option in Upload Files. You could also probably write a little script that did a big more, checked the size, if it’s too big, resize to a resaonable limit, etc.

Permalink | Quote

[7]

bram
Guest
February 19th, 2009 at 5:08 pm

Hi,

I just posted a small explanation for outputting thumbs or medium sized images in templates.

check: this thread

Permalink | Quote

[8]

Mark Cunningham
Guest
February 24th, 2009 at 10:41 am

Using templates is always the most preferred approach to doing things in Wordpress, IMHO.

Permalink | Quote

[9]

enfermatiko
Guest
March 4th, 2009 at 10:28 pm

I was able to limit the accepted dimensions (height x width) for images uploaded by editing the upload-inline.php file but I can’t figure out how to display the image size error correctly instead I’m using die to exit the script. I would like for the upload file form to be reset like it does when there’s an image size error. any suggestions? this is what I added to the script:

if(isset($_POST['tdomf_upload_inline_submit_'.$form_id])) { //see if submit button is pressed.

//check if they decided to upload a pic:
if($_FILES["uploadfile".$form_id."_".$i]['size'] > 1) {

$max_height = 800;
$max_width = 600;

$info = getimagesize($_FILES["uploadfile".$form_id."_".$i]['tmp_name']);

//check the extension.
$array = explode(“.”, $_FILES["uploadfile".$form_id."_".$i]['name']);
$nr = count($array);
$ext = $array[$nr-1];
if(($ext !=”jpg”) && ($ext !=”jpeg”) && ($ext !=”png”))
die(“Error: file extension un-recognized.
Be sure your image follows the correct extension (.JPG or .PNG)”);

//CHECK TYPE: (what the browser sent)
if(($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/jpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] !=
“image/pjpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.”);
}

//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize()
//-In case it was a FAKE!
if(($info['mime'] != “image/jpeg”) && ($info['mime'] != “image/pjpeg”) &&
($info['mime'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.”);
}

//check file size (length & width)
if(($info[0] != $max_width) || ($info[1] !=$max_height)) {
die(“Error: Image size error (” . $info[0] .
x ” . $info[1] . “). Must not exceed “. $max_width .
” x “. $max_height .”.”);
}
}
}

Permalink | Quote

[10]

Mark Cunningham
Guest
March 9th, 2009 at 5:08 pm

Where did you insert this code enfermatiko?

Permalink | Quote

[11]

enfermatiko
Guest
March 9th, 2009 at 8:08 pm

I’ve already solved my problem but this is how the code looks on upload-inline.php

Before code:

// Move the uploaded file to the temp storage path
//
for($i = 0; $i < $options['max']; $i++) {
$upload_temp_file_name = $_FILES["uploadfile".$form_id."_".$i]['tmp_name'];
$upload_file_name = $_FILES["uploadfile".$form_id."_".$i]['name'];
$upload_error = $_FILES["uploadfile".$form_id."_".$i]['error'];
$upload_size = $_FILES["uploadfile".$form_id."_".$i]['size'];
$upload_type = $_FILES["uploadfile".$form_id."_".$i]['type'];

Added code:

if(isset($_POST['tdomf_upload_inline_submit_'.$form_id])) { //see if submit button is pressed.

//check if they decided to upload a pic:
if($_FILES["uploadfile".$form_id."_".$i]['size'] > 1) {

$max_height = 800;
$max_width = 600;

$info = getimagesize($_FILES["uploadfile".$form_id."_".$i]['tmp_name']);

//check the extension.
$array = explode(“.”, $_FILES["uploadfile".$form_id."_".$i]['name']);
$nr = count($array);
$ext = $array[$nr-1];
if(($ext !=”jpg”) && ($ext !=”jpeg”) && ($ext !=”png”))
die(“Error: file extension un-recognized.
Be sure your image follows the correct extension (.JPG or .PNG)Click here to try again“);

//CHECK TYPE: (what the browser sent)
if(($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/jpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] !=
“image/pjpeg”) && ($_FILES["uploadfile".$form_id."_".$i]['type'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.Click here to try again“);
}

//DOUBLE CHECK TYPE: if image MIME type from GD getimagesize()
//-In case it was a FAKE!
if(($info['mime'] != “image/jpeg”) && ($info['mime'] != “image/pjpeg”) &&
($info['mime'] != “image/png”)) {
die(“Error: Upload file type un-recognized. Only .JPG or .PNG
images allowed.Click here to try again“);
}

//check file size (length & width)
if(($info[0] != $max_width) || ($info[1] !=$max_height)) {
die(“Error: (” . $info[0] .
“ x ” . $info[1] . “) is not the correct size. Only “. $max_width .
” x “. $max_height .” images allowed.Click here to try again“);
}
}
}

After code:

if(is_uploaded_file($upload_temp_file_name)) {
// double check file extension

Permalink | Quote

[12]

Mark Cunningham
Guest
March 13th, 2009 at 4:57 pm

Thanks… I may sneak this code! :)

Permalink | Quote

Advertisments

Join the Discussion