Spudhead
08-16-2005, 11:56 AM
I'm using Imagemagick (http://www.imagemagick.org) to let users do some basic optimisation on uploaded images.
The API gives me a "Convert" function, into which I pass my list of actions. I need to enable 3 actions, all of which are optional: set the compression quality, set the rotation, set the image sharpness.
Because the "Convert" function is set up to take a list of parameters, I can't just loop through values, building up a string of commands that I can then pass to the function. I've got to pass in each parameter individually, if it's been set.
The way I've done it is below. I think it's inelegant and far too much code (especially as adding further potential 'actions' is going to require exponentially more and more code), but I can't figure out a way of reducing it.
Any suggestions?
set objImageEditor = server.createobject("ImageMagickObject.MagickImage.1")
if strImageQuality <> "" then
if strImageRotation <> "" then
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, "-rotate", strImageRotation, "-unsharp", strImageUnsharp, strEditedImagePath)
else
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, "-rotate", strImageRotation, strEditedImagePath)
end if
else
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, "-unsharp", strImageUnsharp, strEditedImagePath)
else
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, strEditedImagePath)
end if
end if
else
if strImageRotation <> "" then
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath,"-rotate", strImageRotation, "-unsharp", strImageUnsharp, strEditedImagePath)
else
strMsg = objImageEditor.Convert(strImagePath, "-rotate", strImageRotation, strEditedImagePath)
end if
else
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath, "-unsharp", strImageUnsharp, strEditedImagePath)
else
'no changes
end if
end if
end if
set objImageEditor = nothing
The API gives me a "Convert" function, into which I pass my list of actions. I need to enable 3 actions, all of which are optional: set the compression quality, set the rotation, set the image sharpness.
Because the "Convert" function is set up to take a list of parameters, I can't just loop through values, building up a string of commands that I can then pass to the function. I've got to pass in each parameter individually, if it's been set.
The way I've done it is below. I think it's inelegant and far too much code (especially as adding further potential 'actions' is going to require exponentially more and more code), but I can't figure out a way of reducing it.
Any suggestions?
set objImageEditor = server.createobject("ImageMagickObject.MagickImage.1")
if strImageQuality <> "" then
if strImageRotation <> "" then
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, "-rotate", strImageRotation, "-unsharp", strImageUnsharp, strEditedImagePath)
else
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, "-rotate", strImageRotation, strEditedImagePath)
end if
else
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, "-unsharp", strImageUnsharp, strEditedImagePath)
else
strMsg = objImageEditor.Convert(strImagePath, "-quality", strImageQuality, strEditedImagePath)
end if
end if
else
if strImageRotation <> "" then
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath,"-rotate", strImageRotation, "-unsharp", strImageUnsharp, strEditedImagePath)
else
strMsg = objImageEditor.Convert(strImagePath, "-rotate", strImageRotation, strEditedImagePath)
end if
else
if strImageUnsharp <> "" then
strMsg = objImageEditor.Convert(strImagePath, "-unsharp", strImageUnsharp, strEditedImagePath)
else
'no changes
end if
end if
end if
set objImageEditor = nothing