Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Create fixed Thumbnail sizes using ASPJPEG

Posted on 2010-09-18
8
Medium Priority
?
1,005 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…
Suggested Courses

927 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