How to know what images are used in an app?

Hello all.

I have a lot of images in my project. I want to remove the ones that are not used as part of the compiled app. Is there a function I can run that will tell me? Or, is the output of the compiled app, a resources folder that contains images, limited to only those that are actually used and not all of them?

Thanks in advance,
Tim

The short answer is no.
https://forum.xojo.com/29722-strip-unused-images-resources-from-builds

Thanks Tim.

Bummer…
Tim

A one time only task ?

a. remove one image
b. compile,
c. go back to a.

At b time (compile), if Xojo complain, Cancels the image removal, else continue.

If you really have tons of them, do that with 10 image a time (delete 10 images at once)…

Sometimes ago, I noticed that an image copied in the project was copied in the application even if not used. Is it still the case ?
Try by yourself: add a large image, compile, rename the application (or move it elsewhere), remove it compile and compare both sizes…

Edit:
Doh ! I forgot: Or believe what Tim said.

Tims right.
Yes, they are all copied into the project and all included. At least that is how it appears. When I got rid of all but 35, it ran much much faster…

Tim

To make a test (minutes ago), I set a Canvas into my window and set my window as large as 4500. I et a message at save time about its size and the inability (for this project) to be opened by older IDE (you will need newer IDE to open this project)…

And I used the latest to date released IDE: Xojo 2018r2.

In theory; you might be able to use grep to search the executable for the image name…

Using strings for grep on the binary like this might also take care of images that are added through other means and of which Xojo doesn’t know about until execution (like files added to resources folders and called locally).

There is no way in the IDE to tell. Suppose you have code like:

 if rnd() > .5 then
     bevelbutton1.background = beeker
 else
     bevelebutton1.background = foo
 end if

The question of “is it used” is only known for sure at runtime. Is it likely to be used is a different question…

So the conversation title have to bechanged from:
How to know what images are used in an app?

to:
How to know what images can be displayed in my app ? :wink:

Edit: some words were changed…

msgbox "click the button to display 'beeker'"

would infer that “beeker” is being used, when in fact its just a word in this context

[quote=405053:@Emile Schwarz]So the conversation title have to bechanged from:
How to know what images are used in an app?

to:
How to know what images can be displayed in my app ? :wink:

Edit: some words were changed…[/quote]

The IDE doesn’t have a way to identify which images have not been referred to in code. The only real way to do this is to alter the names of the items and then compile and see which items the compiler complains about.

It’s the exact same issue as knowing which methods have / have not been used.

I understood this to mean “search the binary”, which can be done. Hence:

That’s why I thought “it’s used” meant “it’s included in the compiled application”. If it’s forcefully included by code then it’ll be included (both in the example you gave)

[quote=405054:@Dave S] msgbox "click the button to display 'beeker'"
would infer that “beeker” is being used, when in fact its just a word in this context[/quote]

If images are included from a resources folder (the only way I ever do it) then images should have a proper name. Searching for .png or .jpg would show which names are in the executable. If a name is listed when grepping for strings in the binary then it’s assumed to be used and if i’snt then it’s not.

We can think of cases where you can make your code trick your routine to give false positives, but that seems self-defeating :smiley:

You could just search the sources for the image name and, if it shows up only as the name of the image, then it’s unlikely that it’s used.

Only if the “name” showed up in an executable statement (not a comment) and was not enclosed in quotation marks

There is no simple way other than scanning the app for resource names, and then determining if/where those names do or not appear in the proper context

This is what I meant:

[code]Eduomaca:MacOS eduo$ pwd
/Users/eduo/Temp/SolEol 2.app/Contents/MacOS
Eduomaca:MacOS eduo$ strings SolEol\ 2 |grep ttf
SourceSansPro-Regular.ttf
Eduomaca:MacOS eduo$ strings /Applications/SMBUp.app/Contents/MacOS/SMBUp | grep png
check-circle-1.png
FirmaFake.png
a/System/Library/Frameworks/SecurityInterface.framework/Versions/A/Resources/Lock_Locked State.png
Eduomaca:MacOS eduo$ strings /Users/eduo/Downloads/SMBUp.app/Contents/MacOS/SMBUp | grep jpg
Eduomaca:MacOS eduo$ strings /Users/eduo/Downloads/SMBUp.app/Contents/MacOS/SMBUp | grep gif
btn_donateCC_LG.gif

https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=eduo%40mac.com&lc=US&item_name=Eduo&item_number=SMBUp-1&no_note=1&no_shipping=2&rm=1&return=http%3A%2F%2Feduo.info%2FSMBUp%2Fapi.php%3Fget%3DsuccessDonation&cancel_return=http%3A%2F%2Feduo.info%2FSMBUp%2Fapi.php%3Fget%3DcancelDonation&currency_code=USD&bn=PP-DonationsBF%3Abtn_donateCC_LG.gif%3ANonHosted
Eduomaca:MacOS eduo$
[/code]

Last line is a false positive :smiley:

Right in the IDE just use the Find function and see if the image name is found in source code.

I am failing to see how this would not be full of potential false positives as both Eduardo and I have previously demonstated

in this situation I’d rather have false negatives than false postives

You’re not searching the binary. You’re searching the code that will be compiled in the IDE itself. If the only place you find the name of the image in your sources is in the name of the project item then it’s unused in the source code. The name of the item in a quoted string is not a reference to the image, obviously

ie/ if you have

bevelbutton1.bacground = somePictureIDraggedIntoTheProject

then a search for the name somePictureIDraggedIntoTheProject would find it in at least 2 places

  1. the name of the picture in the navigator
  2. the name in use in this line of code

The same is true if you set as the background of a window, canvas etc to the picture. It will be found by searching and you can see that, indeed, the picture is used.