NetTalk Central

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

bruce2

  • Full Member
  • ***
  • Posts: 108
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #15 on: July 18, 2012, 09:37:24 PM »
what build of NetTalk are you on Ian?
the current build of the example is attached, but it's been in NetTalk a while, so if you don't have it then either you're using a very old build, or you're not looking for your examples in the right place.

Cheers
Bruce


[attachment deleted by admin]

Larry Sand

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Photo Thumbnail - resize proportionally
« Reply #16 on: July 19, 2012, 06:55:06 AM »
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.

Bill,

It is thread safe.  I use it to process product images in our server.  We have a rules based system that fetches product images from vendors that we have agreements with and makes a number of rescaled images to match the needs of the server.  The original images isn't even written to disk, the class can read the image from the buffer NetTalk receives it into, then make the rescaled images and discard the original too large image. The FreeImageClass contains simple methods to rescale, thumbnail, crop, rotate and grayscale.   

We did find a problem with some images that had invalid metadata would gpf the freeimage.dll, they fixed the bug and if you have the latest version of the dll from sourceforge it won't be a problem.

Larry Sand


ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #17 on: July 19, 2012, 07:02:44 AM »
Larry

Is there any documentation anywhere on the various methods in Freeimage?

Thanks

Ian

Larry Sand

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Photo Thumbnail - resize proportionally
« Reply #18 on: July 19, 2012, 07:57:50 AM »
Ian,

The FreeImageClass is a wrapper around the functions in the FreeImage.dll and those are documented in the FreeImage docs on sourceforge.  Open FreeImCl.inc/clw and look at the iImage interface definition for many of the things you can do without the image control.  The code for the image control class is in cfiImgCt.inc/clw but you wouldn't use that when you only want to manipulate an image without displaying it.

For instance, here are the rescale methods:
Rescale             Procedure(*Real fPercentX, *Real fPercentY, UNSIGNED fiFilter),BOOL,Proc
Rescale             Procedure(*Real fPercent, UNSIGNED fiFilter),BOOL,Proc
Rescale             Procedure(UNSIGNED nDstWidth, UNSIGNED nDstHeight, UNSIGNED fiFilter),BOOL,Proc
Rescale             Procedure(*iImage dstImage, Real fPercent, UNSIGNED fiFilter),BOOL,Proc
Rescale             Procedure(*iImage dstImage, UNSIGNED nDstWidth, UNSIGNED nDstHeight, UNSIGNED fiFilter),BOOL,Proc


if you look at the implementation in FreeImCl.clw you'll find that four of the methods all call the fifth one using different arguments.  And that fifth method calls FreeImage_Rescale() the dll function.  You can find the freeimage api prototyped in FreeImg.inc. 

You'll notice that a number of methods take or return iImage interfaces.  To use these you'll need more than one freeimageclass object to pass as an argument.  As an example the Thumbnail method declares a temp freeimage class to pass the interface (eventually) to the rescale method like this:

!--------------------------------------------------------------------------
FreeImageClass.iImage.Thumbnail           Procedure(UNSIGNED nDstWidth, FREE_IMAGE_FILTER fiFilter)
!--------------------------------------------------------------------------
dstImageCl    FreeImageClass
  Code
  dstImageCl.bRetainImage = True
  Self.iImage.Thumbnail(dstImageCl.iImage, nDstWidth, fiFilter)
  Return Self.iImage.ReplaceImage(dstImageCl.pImage)



The methods work like this because many of the freeimage functions return a new image, setting the destination image's bRetainImage property ensures the temp object does not destroy the image while it's cleaning things up.

So in general, if you want to change the image you loaded, use the methods that don't have an iImage interface as a parameter.  And declare another freeimage object to pass to the ones that do.

There are some example apps and prjs installed too.

If you have questions, just shout.

Larry

ianburgess

  • Full Member
  • ***
  • Posts: 119
    • View Profile
    • Email
Re: Photo Thumbnail - resize proportionally
« Reply #19 on: July 19, 2012, 08:19:23 AM »
Hi Larry

Many thanks for your comprehensive answer.

I have started to experiment with FreeImage and have successfully created scaled copies of uploaded photos. I will delve into the clw/inc files and see what else is possible.

I am using "FILTER_BSPLINE" option with the Thumbnail method, but see that there are other possibilities - is FILTER_BSPLINE the best choice and what are the merits of the others?

Thanks again.

Ian

Larry Sand

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Photo Thumbnail - resize proportionally
« Reply #20 on: July 19, 2012, 08:52:53 AM »
Ian,

You're welcome.  There's a discussion of the resampling filters in the appendix of the freeimage documentation.  Though you'll find that almost any of them will work fine for general down-sampling.  It does depend somewhat on the image and I assume you won't know anything about them.  Some of the filters are faster than others with box (FILTER_BOX) being the fastest.

Larry