Score:1

How can I get an icon image to appear in my desktop shortcut?

th flag

How do I get an image to appear in an Ubuntu desktop shortcut?

I am trying to get an icon to appear in my desktop shortcut. I am using Ubuntu 20.04.5 LTS. This is what my desktop file looks like:

[Desktop Entry]
Name=Picture Show
Exec=./MyPrograms/PictureShow/ShoPixLinux
Icon=MyPrograms/PictureShow/PictureShow64.png
Terminal=false
Type=Application

I right-click and select Allow Launching, and it works, except I get a red logo with the international NO symbol (a circle with a cross through it) as the icon. If I add a leading right slash after Icon=, I get no shortcut image, just the title. I have tried the original image in .svg format. I have tried .png images in 44 x 44, 48 x 48, 64 x 64, 128 x 128, and 150 x 150.

What am I doing wrong?

Is there something specific about the color depth of the images? Do the images need to be in a specific location, like usr/share/icons? Do they need to be in a specifically named subfolder? Just what size image should I create for an Ubuntu desktop shortcut?

precise avatar
br flag
Use absolute path names
Score:1
tc flag

Try running this:

install -D MyPrograms/PictureShow/PictureShow64.png ~/.local/share/icons/hicolor/64x64/apps/PictureShow.png

Then change Icon=... to Icon=PictureShow

Usually Icon= entries in .desktop files refer to an icon by its basename (without extension). Icons being installed, for example, at /usr/share/icons/hicolor/{px}x{px}/apps/myprog.png

A program might ship with a range of icons, including a SVG icons in /usr/share/icons/hicolor/scalable/apps/myprog.svg

Files:

/usr/share/icons/hicolor/scalable/apps/myprog.svg
/usr/share/icons/hicolor/32x32/apps/myprog.png
/usr/share/icons/hicolor/64x64/apps/myprog.png
...

.desktop entry:

...
Icon=myprog
...

Users can have locally-installed icons as well in ~/.local/share/icons/hicolor/{px}x{px}/apps/.

amphetamachine avatar
tc flag
@Crash Edited my answer with specific instructions at top
Crash avatar
th flag
I have put appropriately sized pictures into 32x32, 36x36, 48x48, and 64x64, of course in the usr/share/hicolor/sizexsize/apps. Then i changed the text inside the desktop file to Icon=PictureShow36, and I also tried PictureShow42, PictureShow46 and PictureShow48. None of these causes the image to appear in the shortcut. I also tried Icon=PictureShow36.png Still no icon image.
Crash avatar
th flag
or do I need to rename the images so they all have the same name ? ie., take off the indication of the size of the image ?
Crash avatar
th flag
I just ran that line...but nothing seems to have happened. No image in the icon. I changed it back to Pictureshow64.png in the desktop file. Still no image. I tried just PictureShow64, and PictureShow64.png. Then I went back and changed it to Icon=MyPrograms/PictureShow/PictureShow64. Still no image. Then I tried Icon=MyPrograms/PictureShow/PictureShow64.png. Still no image in the shortcut.
Crash avatar
th flag
Thank you for your help. I will be working on this again soon, later today. Last night before leaving I looked up the Install command. What I found talked only about installing programs, not images. The line above that I copied and ran tries to install an image. Is that what you intended, or did you mean to Install the program itself ? And if you did mean to install the program, what all will it do ?
Score:0
cn flag

It will help to provide a correct file path to your image file. Your current path starts with "MyPrograms". That means the system tries to find a directory "MyPrograms" in whatever is the current directory of the process that interprets the launcher.

Icon images may also be indicated by only the base file name of a graphic (i.e., only the name coming before the extension), provided the graphic is located in one of the standard locations. The system will first search for a graphic with that name (and extension either .png, .svg, .bmp) in ~/.icons, ~/.local/share/icons and then in icons directories under the directories enumerated in the XDG_DATA_DIRS environmental variable.

Thus, bottom line:

Either

  • Provide a valid file name in your desktop file, e.g. /home/youruser/MyPrograms/PictureShow/PictureShow64.png. (Tip: find the graphics file in your file manager, then hit Ctrl+c to copy the file path to the clipboard.

  • Place your graphic in ~/.local/share/icons (create that directory if it does not exist, and refer to it in your desktop file with Icon=PictureShow64.

Crash avatar
th flag
That did it. Thank you very much. It was Control-C that did it. I have been having trouble with paths. Using Control-C I had an image showing in my shortcut in 1 minute. In another minute I had the shortcut image working for the other completed program I put on this computer.
Crash avatar
th flag
There's actually quite a bit of useful information in these answers. I used the absolute path to make it work, pointing to a 44 x 44 image. Paths have been difficult because sometimes my name is part of the path, or home, and sometimes not. Sometimes things are shown with some uppercase, and sometimes not. Control-C would have helped my get shortcuts working at all in the first place, much sooner. I wonder...with all those folders for different sized icons, when are other icon sizes used by Ubuntu. Why are so many different image sizes usually provided ?
vanadium avatar
cn flag
If this answer did it, then please show your appreciation by "accepting" it. Feel free to open other questions if you have more.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.