Create fixed Thumbnail sizes using ASPJPEG

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
JamieAsked:
Who is Participating?
 
JamieConnect With a Mentor Author Commented:
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
 
tobzzzCommented:
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
 
JamieAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
tobzzzCommented:
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
 
JamieAuthor Commented:
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
 
Abiel de GrootDeveloperCommented:
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
 
JamieAuthor Commented:
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
 
JamieAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.