Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts

    code logic / layout question - could I do this better?

    I'm using Imagemagick 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?

    Code:
    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

  • #2
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What happens if you call this: objImageEditor.Convert(strImagePath, "-quality", strImageQuality, "-rotate", strImageRotation, "-unsharp", strImageUnsharp, strEditedImagePath) and the variables are null? Some components are designed to ignore them if they are optional. I was just curious if you could just call the Convert method and pass everything in and if it was null that the object would just ignore it.

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Not a bad idea, I'll have a go. Cheers


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •