ActionsDev

9 replies to this thread. Most Recent

Ian Webb

15 Dec 2016, 9:23 am

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

Tim Plumb

15 Dec 2016, 1:14 pm

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 protected]> 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?

Tim Plumb - Experienced Freeway designer for hire

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro

FreewayStyle.com - Free Freeway templates and parts to download, use and explore

Ian Webb

16 Dec 2016, 8:25 am

Hi Tim!

You are a legend. Thank you.

Cheers, Ian.

Tim Plumb

16 Dec 2016, 12:31 pm

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 protected]> wrote:

You are a legend. Thank you.

Tim Plumb - Experienced Freeway designer for hire

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro

FreewayStyle.com - Free Freeway templates and parts to download, use and explore

Ian Webb

16 Dec 2016, 6:39 pm

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.

Tim Plumb

16 Dec 2016, 9:41 pm

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 protected]> 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?

Tim Plumb - Experienced Freeway designer for hire

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro

FreewayStyle.com - Free Freeway templates and parts to download, use and explore

Ian Webb

19 Dec 2016, 12:27 pm

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.

Tim Plumb

20 Dec 2016, 4:12 pm

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 protected]> 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!).

Tim Plumb - Experienced Freeway designer for hire

FreewayActions.com - Freeware and commercial Actions for Freeway Express & Pro

FreewayStyle.com - Free Freeway templates and parts to download, use and explore

Ian Webb

20 Dec 2016, 4:38 pm

Hi Tim!

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

Thanks again, Ian.

Back to Top