NetTalk Central

Author Topic: Photo Thumbnail - resize proportionally  (Read 8418 times)

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Photo Thumbnail - resize proportionally
« on: July 17, 2012, 08:05:49 AM »
I have a form and a browse, both of which display a thumbnal of a much larger photo. The photos all have different different proportions. The problem is that when I specify the size of the thumbnail image, I have to specify both horizontal and vertical size, but I don't know the proportions and therefore have to specify an arbitrary size that most often results in the image neing squased or stretched.

How can I specify one dimension and have the image automatically resize in proportion to original?

Thanks

Ian

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #1 on: July 17, 2012, 06:04:47 PM »
Hi Ian,

Due to an old bug in IE (only IE6 and earlier from memory), Bruce's code forces both the width and the height, and if you don't specify one, NT will guess the other from the parameter you did provide.

You have two choices:

1. determine the width and height of your actual image in question (various methods exist for this) and set the values in the correct aspect ratio, or
2. Locate the function NetWebServerWorker.CreateImage in NetWeb.CLW in the LIBSRC folder and comment out these two lines:

  !if loc:height and not loc:width then loc:width = loc:height.
  !if loc:width and not loc:height then loc:height = loc:width.


Apologies to Bruce for my hack.

If you do #2, don't specify either the width or height on your images and for all browsers (except IE6 and maybe IE7) your images will be fine.

Regards
Bill

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11183
    • View Profile
Re: Photo Thumbnail - resize proportionally
« Reply #2 on: July 17, 2012, 09:22:23 PM »
good point Bill - it's probably worth killing those lines of code at some point.

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #3 on: July 18, 2012, 12:03:40 AM »
Thanks - that did the trick.

An allied question....
By specifying the image size, the "full size" image is still loaded, even though it is displayed as a thumbnail. If the image is very large, then this may cause the page to load slowly, especially if the image is on a browse with a number of lines displayed.

These images are user uploaded, so there is only one version (full size) - is there a way of resizing the image on the server side?

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #4 on: July 18, 2012, 12:14:56 AM »
Yes, but you must use some tool to do it. Personally I use ImageEx (http://www.solidsoftware.de) (but its not reentrant so it must be protected by a critical section). Before ImageEx I used LeadTools.

Basically you are on your own. Its the same a resizing images in a desktop app once you are on the server with the exception of the NT server being heavily threaded.

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #5 on: July 18, 2012, 12:21:04 AM »
Yes, but you must use some tool to do it. Personally I use ImageEx (http://www.solidsoftware.de) (but its not reentrant so it must be protected by a critical section). Before ImageEx I used LeadTools.

Basically you are on your own. Its the same a resizing images in a desktop app once you are on the server with the exception of the NT server being heavily threaded.

Thanks for the recommendation. Presumably you build in some code that creates a thumbnail version when the main image is uploaded...and I just use the thumbnail image when needed in browses etc?

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #6 on: July 18, 2012, 12:25:41 AM »
yeah, exactly. I create thumbnails after upload and put them in sensible places so i can easily use the appropriate image.

I have a wrapper function for ImageEx so its a one liner to create the thumbnail.

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #7 on: July 18, 2012, 12:28:05 AM »
yeah, exactly. I create thumbnails after upload and put them in sensible places so i can easily use the appropriate image.

I have a wrapper function for ImageEx so its a one liner to create the thumbnail.

OK great - looks like it's worthwhile investing in ImageEx. Any chance of "borrowing" your wrapper function?

Cheers

Ian

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11183
    • View Profile
Re: Photo Thumbnail - resize proportionally
« Reply #8 on: July 18, 2012, 12:43:04 AM »
you don't need ImageEx to create thumbnails.
you can use ClarionFreeImage.

Example 26 (File Uploading) contains an example of this - including the necessary FreeImage code to create thumbnails.

see www.clarionfreeimage.com for more information on that side of things.

cheers
Bruce

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #9 on: July 18, 2012, 01:32:06 AM »
you don't need ImageEx to create thumbnails.
you can use ClarionFreeImage.

Example 26 (File Uploading) contains an example of this - including the necessary FreeImage code to create thumbnails.

see www.clarionfreeimage.com for more information on that side of things.

cheers
Bruce


Thanks Bruce. I have looked at Example 26 and cannot see reference to FreeImage?

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #10 on: July 18, 2012, 02:08:57 AM »
Forgot about clarionfreeimage. I'm sure it works great.

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #11 on: July 18, 2012, 03:27:37 AM »
Bruce

Since I cannot find reference to Freeimage code in example, I looked at embedding the following (slightly changed for my filenames) in the WebHandler procedure:

 If ThumbImage.iImage.Load('C:\images\ImageFile.jpg')
    ThumbImage.iImage.Thumbnail(64, FILTER_BSPLINE)
    ThumbImage.iImage.SaveAs('C:\images\ImageFileThumb.jpg')
  End

However, If I embed in the "RenameFile" point, it is too early and the uploaded file has not yet been uploaded - where should I embed so that it is after the file has been uploaded?

Thanks

Ian

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11183
    • View Profile
Re: Photo Thumbnail - resize proportionally
« Reply #12 on: July 18, 2012, 08:02:51 AM »
you could put it in webHandler, but I think it's better in the Form itself.
See the MailboxesFormControl in the example including;

ThumbImage FreeImageClass

and

  If p_web.GetValue('MAI:MailBoxPicture')
    If ThumbImage.iImage.Load(clip(p_web.site.WebFolderPath) & '\' & p_web.GetValue('MAI:MailBoxPicture'))
      ThumbImage.iImage.Thumbnail(64, FILTER_BSPLINE)
      ThumbImage.iImage.SaveAs(clip(p_web.site.WebFolderPath) & '\' & p_web.GetValue('MAI:MailBoxPicture') & '.thumb.jpg')
      p_web.SetValue('mai:mailboxthumbnail',p_web.GetValue('MAI:MailBoxPicture') & '.thumb.jpg')
      mai:mailboxthumbnail = p_web.GetValue('mai:mailboxthumbnail')
    End
  end


cheers
Bruce

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #13 on: July 18, 2012, 08:30:53 AM »
Thanks Bruce.

My example 26 seems not to include the Freeimage stuff. Would you be able to upload the latest example (for C6) to the newsgroup?

Thanks

Ian

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #14 on: July 18, 2012, 03:59:21 PM »
Hi Ian.,

Left me know how you get on with ClarionFreeImage. If it is reentrant (ie. thread safe), unlike ImageEx i might swap over and use it for my thumbnails.

Also, and you probably thought of this. I too have many occasions where a customer may be uploading images. As our customers wouldn't know a megapixel from latte I also accept their original image and if it is above a certain arbitrary size (say 3MP) i'll thumbnail their crazy 10MP image down to 3MP or similar so I don't have to keep shuffling around some huge file just because they bought a new camera and don't know how to use it.

Regards
Bill