Solved

Create fixed Thumbnail sizes using ASPJPEG

Posted on 2010-09-18
8
981 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Obtain data from database .mdb 4 35
JQuery Autocomplete Tag AJAX (Need nice script) 11 77
send email part1 9 53
Table doesn't show the lines! 3 38
I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
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":…

710 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