[Pro] Image sizes

Hi!

I’m sure this should be simple, but I just can’t get it to work. I want to loop through every image on a page and explicitly set the height and width attributes to what’s in the inspector.

This is what I have so far:

	for (var i in imageTags) {
		imageObject = imageTags[i];
		imageObject.width = '"'+imageObject.fwWidth+'"';
		imageObject.height = '"'+imageObject.fwHeight+'"';
	}

But, imageObject.fwWidth is ‘undefined’.

Can anyone tell me what I’m missing please?

Cheers, Ian.


actionsdev mailing list
email@hidden
Update your subscriptions at:

Hi Ian,
From memory the fwWidth and fwHeight properties are only available from fwItem objects and can’t be accessed directly from the tag tree. You could get the width and height of the image from the generated image tag attributes or CSS styles but the easiest thing to do would be to loop through all of the objects and do it that way.

For example;


<action-encoding>UTF-8</action-encoding>
<page-action name="freewayactions.com.actions.setimagesizes" title="Set image sizes">

<action-javascript>

	function fwBeforeEndBody(){
		var allItems = fwPage.fwFindAllItems(true); // find all the children
		for (i in allItems){
			var exportType = allItems[i].fwExportType;
						
			switch(exportType){
			case 108: //passthrough graphic
				setImageSize(allItems[i],allItems[i].fwWidth,allItems[i].fwHeight);
				break;
			case 3: //non passthrough graphic
				setImageSize(allItems[i],allItems[i].fwWidth,allItems[i].fwHeight);
				break;
			}
		}
	}
	
	function setImageSize(theIMGRef,theWidth,theHeight){
		var imageTags = fwDocument.fwTags.fwFindAll("img",theIMGRef);
		for (var i in imageTags) {
			imageObject = imageTags[i];
			imageObject.width = '"'+theWidth+'"';
			imageObject.height = '"'+theHeight+'"';
		}
	}
	
</action-javascript>

</page-action>

I hope this helps.
Regards,
Tim.

On 15 Dec 2016, at 09:23, Ian Webb email@hidden wrote:

I’m sure this should be simple, but I just can’t get it to work. I want to loop through every image on a page and explicitly set the height and width attributes to what’s in the inspector.

This is what I have so far:

  for (var i in imageTags) {
  	imageObject = imageTags[i];
  	imageObject.width = '"'+imageObject.fwWidth+'"';
  	imageObject.height = '"'+imageObject.fwHeight+'"';
  }

But, imageObject.fwWidth is ‘undefined’.

Can anyone tell me what I’m missing please?


actionsdev mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options

Hi Tim!

You are a legend. Thank you.

Cheers, Ian.


actionsdev mailing list
email@hidden
Update your subscriptions at:

No problem Ian. Let us know how the Action goes and if you need any other help.
Regards,
Tim.

On 16 Dec 2016, at 08:25, Ian Webb email@hidden wrote:

You are a legend. Thank you.


actionsdev mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options

Hi Tim!

It didn’t work for non-passthrough GIF, which I worked out was fwExportType 2, so I added another case for that. Do you think there may be other export types we may be missing?

Cheers, Ian.


actionsdev mailing list
email@hidden
Update your subscriptions at:

Hi Ian,
Yes I’d overlooked the export types that you’d want to use. On reflection I’d be inclined to pass every object on the page to the setImageSize function as only the images will get picked up by the var imageTags = fwDocument… line.

The modified Action would look like this;

<action-encoding>UTF-8</action-encoding>
<page-action name="freewayactions.com.actions.setimagesizes" title="Set image sizes">

<action-javascript>

	function fwBeforeEndBody(){
		var allItems = fwPage.fwFindAllItems(true); // find all the children
		for (i in allItems){
			setImageSize(allItems[i],allItems[i].fwWidth,allItems[i].fwHeight);
		}
	}
	
	function setImageSize(theIMGRef,theWidth,theHeight){
		var imageTags = fwDocument.fwTags.fwFindAll("img",theIMGRef);
		for (var i in imageTags) {
			imageObject = imageTags[i];
			imageObject.width = '"'+theWidth+'"';
			imageObject.height = '"'+theHeight+'"';
		}
	}
	
</action-javascript>

</page-action>

It may run slightly slower than before as we’re looking for image tags in every object but it should only be a fraction of a second different if at all.

If you still wanted to use the fwExportTypes then the full list I have is;
Other = 0 // Plugins, applets, pass-through graphics
HTML = 1
GIF = 2
JPEG = 3
URL = 4
PNG= 5
Area Map = 6
Checkbox = 100
Radio = 101
Button = 102
TextField = 103
List = 104
TextArea = 105
Java = 106
PlugIn = 107
External Graphic = 108
QuickTime = 109
Flash = 110
Text = 111
HTML Markup = 112

Regards,
Tim.

On 16 Dec 2016, at 18:39, Ian Webb email@hidden wrote:

It didn’t work for non-passthrough GIF, which I worked out was fwExportType 2, so I added another case for that. Do you think there may be other export types we may be missing?


actionsdev mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options

Hi Tim!

Yes, I think passing every object is fine. The action is a companion to the HTML e-mail action that allows high-resolution/Retina images to be used (as Outlook needs explicit height and width attributes instead of CSS to display them at the right size), so it’s only going to be used on a few pages at a time.

Thanks again for your help with this (or, to be more exact, thank you for writing this action for me!).

Cheers, Ian.


actionsdev mailing list
email@hidden
Update your subscriptions at:

Not a problem Ian. I like a challenge and generally like writing Actions too.
I’m glad you’ve got it all working as you want it.
Regards,
Tim.

On 19 Dec 2016, at 12:27, Ian Webb email@hidden wrote:

Yes, I think passing every object is fine. The action is a companion to the HTML e-mail action that allows high-resolution/Retina images to be used (as Outlook needs explicit height and width attributes instead of CSS to display them at the right size), so it’s only going to be used on a few pages at a time.

Thanks again for your help with this (or, to be more exact, thank you for writing this action for me!).


actionsdev mailing list
email@hidden
Update your subscriptions at:
https://freewaytalk.softpress.com/person/options

Hi Tim!

Cool. I’ll post it to ActionsForge and credit you.

Thanks again, Ian.


actionsdev mailing list
email@hidden
Update your subscriptions at:

http://actionsforge.com/actions/hi-res-e-mail-images


actionsdev mailing list
email@hidden
Update your subscriptions at: