Application demo help needed

I would like the image size to be checked to see if it is larger than 640 x 480 or 480 x 640 and if it is resize it to those sizes within the aspect ratio then save the file.

I'm willing to pay someone if needed to get this done. Thanks.

gyphie's picture

Already does this

The application demo already does this. But it then stretches out the image edges so it's always 100x100.

You just need to remove that bit of code so it doesn't stretch out the image. Replace lines 67 through 74 (in the latest version from the SVN) with this:

final_image = new System.Drawing.Bitmap(new_width, new_height);
graphic = System.Drawing.Graphics.FromImage(final_image);
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphic.DrawImage(original_image, 0, 0, new_width, new_height);

gyphie's picture

Oh and...

Also, you need to update the target_width and target_height values to be 640 and 480 (instead of 100 x 100)

You'll also need to add an image size check if you don't want images smaller than 640x480 to be enlarged.

what file is that code

what file is that code located in?

gyphie's picture

It's in upload.aspx.cs.

It's in upload.aspx.cs. That's where the image is received and processed (and in the demo it's stored in a session variable).

i'm using the php version of

i'm using the php version of the applicationdemo, in the upload.php file which lines should i look at?

thanks

gyphie's picture

Oh...php

I don't know why I assumed you were using the .Net version.

Well basically you make the same changes:

In upload.php:
on line 60 change the (100, 100) to ($new_width, $new_height)
remove lines 61 through 65
on 67 it does all this stuff to center the thumbnail (it's the 2 parameters that get divided by 2). Just replace these with 0.
Oh, and change your target sizes on lines 39 and 40.

That should work Smiling

There is probably a better way to do it. Use the PHP website to research the "image" functions. That's how I figured it out.

thanks, the changes worked

thanks, the changes worked perfectly. I have one more question. I'm trying to detect if the user image is too small and then output an error message. The coding below works but the error message is not being output. It just says "500" and not the error message the I set.


if ($width < 160 || $height < 120 ) {
header("HTTP/1.1 500 Internal Server Error");
echo "Invalid width or height. Your image is way to small.";
exit(0);
}

gyphie's picture

Returning data to SWFUpload

Returning the 500 status code triggers an uploadError event but Flash will not return any server data.

In order to return server data you have to return a 200 status code (which is the default in most cases). This will trigger an uploadSuccess event in SWFUpload with the server data your return.

You'll have to do some logic in your event to let the user know there was an error.

Something like this:


if ($width < 160 || $height > 120 ) {
echo "Invalid width or height. Your image is way too small.";
exit(0);
} else {
echo "Success";
}

and this


uploadSuccess(file, server_data) {
if (server_data !== "Success") {
alert(server_data); // Show the error message
}
}

(p.s. This all assumes you are using the Flash 9 version)

thanks for the coding, but

thanks for the coding, but it didn't work. nothing happened after adding the new coding you gave. I double checked to make sure i'm running flash 9