6

We have a photo image formula field thats showing student photos, using the technique found here:

http://assets.salesforce.com/pdf/getting_started_with_images_v1.pdf

(alternate link: http://www.eltoro.it/servlet/servlet.FileDownload?file=00PA0000007KWj1MAG)

the problem is that not all the photos are the same aspect ratio and some of them are really really large. So I want to scale them down but only in one dimension, bit if i added just width to the image() tag in the formula it wont let me save it, so I have to add width and height which is causing all of the images to stretch?

Is there a way to just scale the image proportionally by just adjusting the width and not the height or vice versa?

this is the formula we are using

IMAGE('http://posse.force.com/photos/servlet/servlet.FileDownload?file='+LEFT(SYSTEM_Photo_Id__c,15), 'Student Photo', 200, 200)

2 Answers 2

4

Doesn't look like it, using the IMAGE formula directly. A few options I would suggest.

  • as part of your normal business process, re-scale the images upon upload. Obviously depending on the process and/or personnel involved, or if they are self-service uploads, this may not be feasible.
  • do a nightly / hourly / whatever rescale of all new images. This would be a pretty easy task via an API integration and the excellent ImageMagick library.
  • if changing your upload process to introduce a scaling step, or a nightly rescale, is undesirable, you could introduce a middle-man server to do the scaling on the fly. So a URL like 'http://posse.force.com/photos/servlet/servlet.FileDownload?file='+LEFT(SYSTEM_Photo_Id__c,15) becomes something more like 'http://myimagescaleserver/scale?sfid='+LEFT(SYSTEM_Photo_Id__c,15)+'&width=150'

For option 3, there is a discussion here with some interesting options, including the little tidbit that Google Docs supports dynamic image resizing which I was not aware of. Image Resizer also seems like a pretty good server option, and it's free.

EDIT: realized I left out a fourth option, which is a hack but it seems like a pretty common approach to this sort of issue. You use a sidebar component with some JavaScript (usually backed by jQuery) which looks at your page, finds the profile image (probably by combination of table location and URL), and then dynamically resizes it. It's a hack because Salesforce doesn't recommend DOM manipulation and doesn't guarantee that anything will remain the same from release to release, etc. but I've seen similar things done at several clients in the past. Here's an example of what this sort of page-manipulation component looks like.

EDIT 2: just found this thread which has what look to be pretty viable middle-man options that are already around and look pretty easy to use (and mostly free!), if you don't mind a third party processing your images.

3
  • 1
    The one thing that's been left out of this discussion is that resizing alone may not produce the desired results. Depending on the image's proportions, it may need to be cropped either before or after it's been resized (I include after because images can be made larger or smaller).
    – crmprogdev
    Mar 29, 2013 at 7:01
  • @crmprogdev - yes absolutely, that was only (poorly, by my choice of the words "crop" and "scale") implied in my answer. All of the options I mention would be compatible with a "pad or crop" and/or a "resize one dimension only" strategy. When I've had to deal with this issue in the past, I've always found the best solution is to use something like ImageMagick to resize all images to exact desired dimensions using white or transparent padding in the deficient axis.
    – jkraybill
    Apr 1, 2013 at 3:35
  • No problem. I've been using Photoshop since ver 2.5, the 1st available for the PC, so am probably more aware of aspect ratios, cropping and other related issues when it comes to sizing images for use on the web than the average Joe. In my experience, there's no easy solution when it comes to bulk processing of images that doesn't involve some amount of human intervention if one wants to balance control over quality with content.
    – crmprogdev
    Apr 1, 2013 at 13:50
6

Well actually I've found a way doing it!
Using -1 as the value for the value you want to be set equivalently to css "auto".
e.g:
IMAGE(url,"alt text", 100, -1)
It will actually make the browser ignore this css setting and give it the default "auto" value.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .