Solved

Create fixed Thumbnail sizes using ASPJPEG

Posted on 2010-09-18
8
972 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 5

Expert Comment

by:Abiel de Groot
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
In this second Micro Tutorial in the series,  viewers will learn more basic shortcuts and functions of Illustrator. In this tutorial you will learn about the eyedropper tool, zoom , ellipses and more.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…

744 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

13 Experts available now in Live!

Get 1:1 Help Now