When trying to upload/save a .gif file I am getting the following error "Arithmetic operation resulted in an overflow.". Here is the code where the error occurs.
Telerik.Web.UI.ImageEditor.EditableImage img = e.Image;
if (img.Width > 600 && img.Height > 600)
img.Resize(600, 600);
img.Image.Save(sFullPath + sFileName + sExt);
if (img.Width > 150 && img.Height > 150)
img.Resize(150, 150);
img.Image.Save(sFullPath + sThumbName + sExt);
I added the code to check the size of the image before calling the Resize but it still throws the error. How do I fix this?
17 Answers, 1 is accepted
I tested the problematic resizing logic with the image-uploading approach from this demo, but everything behaves properly on my side. The image gets resized properly and it is successfully saved with the new dimensions. For convenience I am attaching my test page to this reply - please review it and see whether it differs somehow from the one used by you. Are you able to replicate the same problem with it?
Regards,
Vessy
Telerik
Thanks for the reply and the demo. Yes, I have the same and another issue with what you sent. I am attaching a screenshot of the error as well as the two .GIF images I am using. (It wouldn't let me attach them all....so this is one that causes an error even in y our code) Other images seem to resize just fine, but .gifs do not.
Is this a bug? How do we get this fixed so we can release our software update ASAP!
Thank you for the attached image. Unfortunately I am still not able to replicate the problem. Can you take a look over the video from my test here and see whether I am not leaving anything out? I tested the code in Firefox, IE10 and Chrome with the latest version of the controls (20152.826).
Unfortunately we cannot be of much help without being able to reproduce and examine the issue on our side. Should you deem anything else as a possible hindrance that we might have missed so far, do not hesitate to inform us, so that we can investigate it further.
Regards,
Vessy
Telerik
Thanks. I do not see a video.
I do not know what you need to reproduce it but it is definitely an issue we need to get resolved ASAP as it is holding up our software release, so any help would be appreciated. Here is a video of my own where you can see the issue happening. You can see I have the exact same photo (size, etc) except once it was saved as a .GIF and the other is saved as a .JPG. The .jpg version works fine. The .gif errors out on the resize code. There is definitely a bug there.
http://www.youtube.com/watch?v=zBdNGTX_IC0
Please, excuse me for the lapse - the link to the created video is available here: http://screencast.com/t/SJiDqYcp0AS
We understand that you need the issue resolves and are trying to help, but will need your assistance in order to determine the cause of the problem. Can you answer the questions below?
- Which version of the controls is used in your application? Is it 2015.2.826 like stated in the ticket info?
- In which browser and its version does the issue occur? From the recorded video I can see that the save button gets broken after click, which is an issue for IE compatibility mode and IE7. Can you verify that you are not using one of this browser modes which are not supported?
- Can you try to replicate the issue into a stand alone runnable project and send it so we can test it on our side? I assume that there may be some specific part of your project configuration that might be the missing puzzle.
- Can you saving handler where the problem is thrown and check the value of the img variable? Is it correctly pointing to the editable image object?
Looking forward to your reply,
Vessy
Telerik
Hello Vessy,
Thank you for the reply. As I noted in one of my previous responses, I did also receive the error with the images I also previously attached in your test version as well.
Which version of the controls is used in your application? Is it 2015.2.826 like stated in the ticket info?
>> It look like it is 2015.1.401 according to the Telerik Control Panel
In which browser and its version does the issue occur? From the recorded video I can see that the save button gets broken after click, which is an issue for IE compatibility mode and IE7. Can you verify that you are not using one of this browser modes which are not supported?
>> Chrome Version 45.0.2454.99 m and Firefox 41.0
Can you try to replicate the issue into a stand alone runnable project and send it so we can test it on our side? I assume that there may be some specific part of your project configuration that might be the missing puzzle.
Can you saving handler where the problem is thrown and check the value of the img variable? Is it correctly pointing to the editable image object?
>> It is not working with the images I sent in the version you sent to me. I can work on another standalone app I guess, but that is already not working.
Thank you for spending time on isolating the problem. My assumption is that the problem is related with some configurations on an application level. My suggestion is to compare both the configurations of your original project and the isolated one and see how they differ.
Regards,
Vessy
Telerik
Hello,
I agree obviously there is something in the full project that is in conflict, my hope was you could point me into what would cause the Resize function on the ImageEditor to throw the 'Overflow' error since the error is coming directly from the Telerik control, it is hard for me to figure out beyond this. The isolated project had the same web.config file and the save code is exactly the same as well. I will keep looking but if you have any ideas on where would be the most productive that would be great since I don't really have days to spend on this.....Thanks!
The graphics core of RadImageEditor is the .NET standard GDI+ library and there are some limitations coming from it that cannot be controlled by us. We do want to help you in resolving the problem, but as we are not previously aware of such behavior there is no much we can do without being able to replicate and examine the case on our side.
The only remaining suggestion I can give you is to test the problematic image directly by resizing it through GDI+, without going through the RadImageEditor's API and see whether the problem still persist. In order to make such a test you have go go through the following steps:
- De-archive the attached zip inside the Root folder of the problematic project (the initial one, not the isolated version)
- Open GDIResize.aspx.cs file and change the path passed to the original image object in order to point one of the problematic images
Please make the test above and let us know the results from it.
Regards,
Vessy
Telerik
Hello Vessy,
Thank you for your continued help! I did exactly what you suggested and still get the attached error?...
How can we accomplish uploading a .gif file and resizing it?
Okay, in comparing what you sent to what we have I see that in the 'test' with GDI the image is defined as follows:
Bitmap originalImage = new Bitmap("C:\\dt7odrjbc.gif");
Image img = (Image)originalImage;
** so img is a System.Drawing.Image
In our code we have the following:
Telerik.Web.UI.ImageEditor.EditableImage img = e.Image;
** So img is a Telerik.Web.UI.ImageEditor.EditableImage
The "Resize()" method is called on the image so I am assuming those are different between the two types of images?
So it looks like the resize on the ImageEditor image is the issue.
Okay so I made some changes to make our code use the System.Drawing.Image from the ImageEditor to do the resize using the method you provided in the test. Here is the new code:
string sFullPath = Server.MapPath(Dog.GetDocumentDir(lDog) + "/");
string sExt = "." + e.Image.Format;
string sFileName = Guid.NewGuid().ToString();
string sThumbName = sFileName + "_t";
Telerik.Web.UI.ImageEditor.EditableImage img = e.Image;
System.Drawing.Image originalImage = img.Image;
if (img.Width > 600 && img.Height > 600)
originalImage = Resize(originalImage, new Size(600, 600), InterpolationMode.Bicubic);
originalImage.Save(sFullPath + sFileName + sExt);
if (img.Width > 150 && img.Height > 150)
originalImage = Resize(originalImage, new Size(150, 150), InterpolationMode.Bicubic);
originalImage.Save(sFullPath + sThumbName + sExt);
While I no longer get an error uploading the attached gif, the resized image is 'skewed' and not proportional....
The Resizing logic provided in my previous reply is the resizing logic used inside RadImageEditor. The EditableImage contains an System.Drawing.Image instance of the currently edited image and use it during the resizing process.
As for the proportions of the resized image, it is expected as the image is resized to 150x150 in width and height in the given by me sample. You will need to keep the width:height proportion of the image before the resizing in order to resize it depending on that:
protected
void
RadImageEditor1_ImageSaving(
object
sender, ImageEditorSavingEventArgs e)
{
string
sFullPath = Server.MapPath(
"~/Uploads/"
);
string
sFileName =
"testImage"
+ DateTime.Now.Ticks;
string
sExt =
".gif"
;
string
sThumbName = sFileName +
"_thumb"
;
Telerik.Web.UI.ImageEditor.EditableImage img = e.Image;
int
newHeight;
if
(img.Width > 600 && img.Height > 600)
{
newHeight = (
int
)(600 * (
double
)img.Height / img.Width);
img.Resize(600, newHeight);
}
img.Image.Save(sFullPath + sFileName + sExt);
if
(img.Width > 150 && img.Height > 150)
{
newHeight = (
int
)(150 * (
double
)img.Height / img.Width);
img.Resize(150, newHeight);
}
img.Image.Save(sFullPath + sThumbName + sExt);
e.Cancel =
true
;
}
Regards,
Vessy
Telerik