Javascript image rotate + resize needed

Status
Not open for further replies.

technophile

Ars Legatus Legionis
23,768
The scaling is pretty easy, just set the image element's width or height (if you want to maintain aspect ratio, only set one of them and set the other to auto).

jQuery:
Code:
$('img#img1').css('width', '150px').css('height', 'auto');

For rotation, do you mean e.g. turn it upside down, or rotate it among a set of images (i.e. replace it with the next in the set)? For the former, see here. The latter should be easy to find.
 
let me clarify

by image rotation I mean a slideshow. most of the other code I'm finding doesn't work. it just sits there not rotating

there's both vertical and horizontal images that need to be scaled down a percentage amount to keep their original ratio. I have php code that scales wonderfully for outputting the img tag so it'd be ok if the slideshow code had an option to hard set the size as I could script the numbers here. I've looked at a dozen pieces of slideshow code and none of them set the size


I did find one function that worked wonderfully for rotating but I haven't figured out how to do the dynamic scaling with it too

how would I work with this code to add my scaling?

I might just have to manually make a set of images, but I really don't want to

http://www.dyn-web.com/code/rotate_imag ... tation.php
 

technophile

Ars Legatus Legionis
23,768
From that page:

About Image Size Variation
If you place the first image in your page source and include height and width attributes in the image tag, subsequent images not that size will be resized to fit those height/width specifications. If you do not include height and width attributes, current browsers will display the images at their actual sizes and reflow page content as needed. You can set width and height on a containing element large enough to accomodate the largest image to be rotated in to avoid document reflow.
Just set either a height or width (but not both) on the original img tag and all the images will be resized (keeping their original aspect ratio) to fit that size.
 
technophile":2n81m3cz said:
From that page:

About Image Size Variation
If you place the first image in your page source and include height and width attributes in the image tag, subsequent images not that size will be resized to fit those height/width specifications. If you do not include height and width attributes, current browsers will display the images at their actual sizes and reflow page content as needed. You can set width and height on a containing element large enough to accomodate the largest image to be rotated in to avoid document reflow.
Just set either a height or width (but not both) on the original img tag and all the images will be resized (keeping their original aspect ratio) to fit that size.

yes, but I'm back to the original problem or setting the appropriate size dynamically when the slideshow changes from one where the width needs to be 100 and the next where the width needs to be 150.

because they're really the same size image turned 90% for vertical and I want them to stay that way

I can do this fine in php for static images but not javascript. partially because there's a bug is firefox for javascript still...

thus I'm looking for a slideshow script with hard coded image sizes per image. does anyone know of this? there's too many different slideshow scripts out there to dig through that are junk from 2002 and the terms are too common for good googling

I would like it if someone could show me how to edit that code I linked to set the size using javascript so that the size changes with each new image loaded
 

topham

Ars Legatus Legionis
13,756
Subscriptor
You don't need javascript to force a maximum size. But you may need to fiddle with it a bit for IE.

This Style sheet allows me to force image sizes with proper scaling. The images I used are displayed in a table with a defined height. Images auto-scale to fit.

It isn't perfect however, because IE requires toggling of the compatibility mode for it to display correctly. I haven't gone back to resolve that issue, it may just require a different doc type.
 
I already have my sizing working with php. works wonderfully in every browser

I just need the code to set the size manually on the image using javascript and change with the slideshow image change

if it can't be done, can someone just say so? because if so, I'm either not going to rotate or manually scale the images down and stick them in a seperate folder
 
Status
Not open for further replies.