Solved

Create fixed Thumbnail sizes using ASPJPEG

Posted on 2010-09-18
8
974 Views
Last Modified: 2012-05-10
Hi All,

I have a large number of images, which I want to resize using ASPJPEG to thumbnails, so they are no bigger than 100 pixels high x 100 pixels wide - whilst maintaining the orginal aspect ration - this bit I can do...

... What I need help with, is that once resized,the images could be;

a. 50 high x 100 wide or
b. 100 wide x 50 high etc

I want the resulting image, that I will resave, to have a fixed thumbnail size of 100x100 - ie placing the resized image, centered into a blank, white 100x100 box - this is where I am stuck!

Any help would be greatly appreciated.

Many thanks

Jamie
0
Comment
Question by:Jamie
  • 5
  • 2
8 Comments
 
LVL 11

Expert Comment

by:tobzzz
ID: 33707552
If I understand you correctly, it sounds like you've done all the hard work in ASPJpeg resizing and you simply want to center the image in a white box, 100 x 100. If so the most straightforward way would be to put it in a table. You could also do it in a div but it's not easy to vertically center things in divs.

e.g.
<table cellpadding="0" cellspacing="0" border="0">
  <tr>
    <td width="100" height="100" align="center" valign="center">
      <img src="images/001.jpg" border="0">
    </td>
  </tr>
</table>

As an aside, in ASPJpeg you can resize and crop so your thumbnail is exactly 100x100. You would lose some height or width from the original of course but as it's only a thumbnail not the full size version perhaps it wouldn't matter?

/ Tobzzz
0
 

Author Comment

by:Jamie
ID: 33707828
Hi tobzzz,
Many thanks for your reply. Unfortunately, the images are displayed by a 3rd party application, so I cannot control the htlp that displays the thumbnails, hence for display reasons that the images have to be 100 x 100 themselves.
thanks
Jamie
0
 
LVL 11

Expert Comment

by:tobzzz
ID: 33707866
Sorry Jamie, I'm not clear on what the question is then. Can you clarify? Are you wanting to resize an image using ASPJpeg to be 100x100 without aspect loss (e.g. cropping)?
0
 

Author Comment

by:Jamie
ID: 33708095
Hi tobzzz,

Yes, that is correct the images has to be resized to 100x100, but must maintain the orginal aspect ratio - which means it may not be 100x100 once resized, it could be 100 x 75, so would need to be padded around the edges to make the image centered and 100 x100.

I think I need to use AspJpeg Picture in Picture  - http://www.aspjpeg.com/manual_06.html but not worked out how to use it as yet?

thanks

Jamie
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:Abiel de Groot
ID: 33708393
I do that. First I use ASP upload to run the actual upload then pass it to ASP Jpeg to rezise proportionally.

See the code below.

Kind reagrds

A


' ASP Jpeg Resize

MaxImgWidth = 400

MaxImgHeight = 300

'*************** Icon Pic ********************************

Set PalletImage = Server.CreateObject("Persits.Jpeg")

PalletImage.OpenBinary( FileLargePic.Binary )



'Set Max hight of width

If PalletImage.OriginalWidth > PalletImage.OriginalHeight Then



   If PalletImage.OriginalWidth < MaxImgWidth Then

   PalletImage.Width = PalletImage.OriginalWidth

   Else

   PalletImage.Width = MaxImgWidth

   PalletImage.Height = PalletImage.OriginalHeight * MaxImgWidth / PalletImage.OriginalWidth

   End If

Else



   If PalletImage.OriginalHeight <  MaxImgHeight Then

   PalletImage.Height = PalletImage.OriginalHeight

   Else

   PalletImage.Height = MaxImgHeight

   PalletImage.Width = PalletImage.OriginalWidth * MaxImgHeight / PalletImage.OriginalHeight

   End If

End If

Open in new window

0
 

Author Comment

by:Jamie
ID: 33708555
Hi Jonbysoft:
Thanks for your reply. Whilst it does resize the orginal image so the height or width do not exceed the maximum specified, it unfortunately does not then force the entire image to be padded to the whole 100 x 100.
e.g.
1. Orginal image is 300 high x 165 wide.
2. Resize image to maximum 100 (maintain aspect ratio) , so resized image =  100 high x  55 wide
3. Need image to be 100 x 100.
4. So 100 height is fine, but width, 55 needs to be padded with larger canvas to make it 100 - i.e. 22.5
5. Vice versa if width is 100, but height is 100.
thanks
Jamie
0
 

Author Comment

by:Jamie
ID: 33710456
Hi all,

I've got very close to sorting this now - but the padded areas are black, not white - so trying to solve that at the moment. I've installed the lastest version of aspjpg to our server also, version 2.2.

===============================
GetImage  = UseImage

Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", GetImage
objHTTP.Send

' Create a "blank" image
Set BlankImage = Server.CreateObject("Persits.Jpeg")
BlankImage.New 100, 100, &HFF0000FF              
 
' Draw this image on blank image
Set ProdImage  = Server.CreateObject("Persits.Jpeg")
ProdImage.OpenBinary(objHTTP.responseBody)

' Resize to 100x100 whilst maintaining aspect ration
ProdImage.PreserveAspectRatio = True
  If ProdImage.OriginalWidth > 100 or ProdImage.OriginalHeight > 100 Then
    If ProdImage.OriginalWidth > ProdImage.OriginalHeight Then
      ProdImage.Width = 100
    Else
      ProdImage.Height = 100
    End If
  End If

' Draw frame around thumbnail
BlankImage.Canvas.DrawBar 1, 1, 101, 101

' center image inside frame vert or horiz as needed
BlankImage.Canvas.DrawImage (100 - ProdImage.Width)/2, (100 - ProdImage.Height)/2, ProdImage

BlankImage.Save FindImage
===============================

thanks

Jamie
0
 

Accepted Solution

by:
Jamie earned 0 total points
ID: 33710576
Hi All,
Sorted - please see below!
=================================================================================
GetImage  = UseImage

Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", GetImage
objHTTP.Send

' Create a "blank" image
Set BlankImage = Server.CreateObject("Persits.Jpeg")
BlankImage.New 100, 100, &HFFFFFF
 
' Draw this image on blank image
Set ProdImage  = Server.CreateObject("Persits.Jpeg")
ProdImage.OpenBinary(objHTTP.responseBody)

' Resize to 100x100 whilst maintaining aspect ration
ProdImage.PreserveAspectRatio = True
  If ProdImage.OriginalWidth > 100 or ProdImage.OriginalHeight > 100 Then
    If ProdImage.OriginalWidth > ProdImage.OriginalHeight Then
      ProdImage.Width = 100
    Else
      ProdImage.Height = 100
    End If
  End If  
 
' center image inside frame vert or horiz as needed
BlankImage.Canvas.DrawImage (100 - ProdImage.Width)/2, (100 - ProdImage.Height)/2, ProdImage
   
BlankImage.Save FindImage      
=================================================================================
thanks
Jamie
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Not only does Prezi allow you to create non-linear presentations, it also makes it easy to apply transition animations between your frames. Learn how to apply a fade-in transition to select items and entire frames in this tutorial Select "Edit Path"…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now