Sphinx adding a link to an image or a figure - python-sphinx

I am trying something rather basic in Sphinx. I have some images, but I prefer to keep them pretty small, and I want to allow the user to click on them to get the larger image.
I do not find a syntactic way to combine image: or figure: with ref: or link:.
.. image:: _static/my_image_small.png
and I have in the same folder my_image_large.png.
If you come up with a solution, should the larger image just be a file with an explicit link to it or do I create a reSt file with an additional image: tag?
An alternative could be to play with the image sizes in the reSt file, but then I still do not know how to create the link from the small image to the large image.
Thank you for helping me.

Just use the target directive. You would end up with something like:
.. image:: _static/my_image_small.png
:target: _static/my_image_large.png
It is not strictly necessary to use the references to the static folder in your source. They will be copied to the _images folder anyway when you build the docs (so you will have them twice in your builds, without needing them there).
I always use a folder called figures next to the source folder where I manage the images. The my_image_large.png files, however, you would want to place in the _static folder as the contents will be copied on build.

Related

Is there a way to link yet to be created images into an indesign layout?

I'm creating a multipage publication with many ads that haven't been built yet. I know their size, and filename, but the image/pdf doesn't exist yet.
Is there an existing script or a possible way to link an image that doesn't exist? Another way to look at this would be kind of the reverse of how the missing links (relink) button works. Where I know what the file path will be, but the file is missing.
Publishing industry standard practice:
Rather than a script, just create a blank image at the exact size. Make it florescent magenta with the letters "FPO" huge and dead-centre so no one can mistake it for the real thing.
Importantly: give this FPO image the exact file name of the file which will eventually be used/placed.
When your production image is finalized and approved, cut-and-paste the exact FPO file name into the new file. Drop the production file into your working directory overwriting the FPO file, and refresh it in InDesign. Bob's your uncle.
If this is being done to hundreds of images, you can develop your own batch process to handle this with some time-saving automation. However, this is a good example of an issue that can be solved at the production-management level, rather than at the coding level.
Hoping this helps!

Resource pictures not include in directory

I am creating a vb6 application now and most of my command buttons were graphical style. Do the background images still show up even if I remove them from the app folder?
This is part of what goes into .FRX, .CTX, etc. files. Those are resource files created in a private "property bag" type format and are used to hold things like binary data, images, long strings, and so on.
But don't discard your source files, because you may need them down the road. Treat such things as valuable parts of the program source. They are not needed at run time though.
As far a I know it doesn't remove the picture from the command button when you delete it from the app folder, i suggest making a copy of your image and then delete the original and see if it works in case it doesn't you have the backup image, good luck.

Embed images using FlashDevelop - AS3

I'm not finding much documentation on embeding images in .as files. Really, I'd like to have some theory on it. So far from what I got reading here and there:
I placed an image in Assets folder inside src. Then right-clicked the image and clicked "Generate embed code", then this code line appears where the cursor was [Embed(source="fluffybunny.png")] what now? How do I assign it to a variable or something... I really didn't find it out there.
Instead of given object using .graphic atribbutes I want to use an image.
Also, does it have to be an .SWF?
There are quite a few resources on this (when you search for "as3 use embed tag"). Some of them are really helpful:
http://www.bit-101.com/blog/?p=853
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf680e1-7ffe.html
The most basic thing is that you declare a variable of some type. And you use the [Embed] tag before the variable declaration. It's some kind of weird association. Something like:
[Embed(source="image.jpg")]
public var imageClass:Bitmap;
// later on you can instantiate it and use:
addChild(new imageClass()); // creates and adds new image
This is just a sample - there are a lot of types and ways to do it - give a shot the Adobe reference, there are tons of samples.

Linking to figures in Sphinx

I have some images in my documentation created as a set of reST files in Sphinx. I prefer to keep them pretty small, and I want the user to click on them to get the larger image. The smaller image is not for file size reasons but for presentation reasons. I do not find a syntactic way to combine the tags image: or figure: with ref: or link:.
.. image:: _static/my_image_small.png
and I have a bigger version in the same folder: my_image_large.png.
If you come up with a solution, should the larger image just be a file with an explicit link to it or do I create a reST file with an additional image: tag? An alternative could be to play with the image sizes in the reST file, but then I still do not know how to create the link from the small image to the large image. Is there a way to bypass the Sphinx generator and just give the HTML that I want?
There are two ways you can do it.
The first is to just insert a bit of "raw" HTML:
.. raw:: html
<a href=....><img src=....
The second is to make the image clickable. That way you can link it to a bigger image:
.. image:: _static/my_image_small.png
:target: _static/my_image_large.png
There are more options you can give, btw. See the full list in the restructured text documentation.

Thumbnail-like behavior using target attribute of image directive

I use Sphinx to generate some docs. I have a reStructuredText document and I'd like to put an image into it. The case is that the image should be clickable so that after a user clicks the image then they should be shown this image in full size. I use the image directive and its target option like this:
.. image:: /images/some_image.png
:alt: Image descripion
:align: center
:target: `big_some_image`_
.. _big_some_image: /images/some_image.png
The problem is that in the rendered page I get:
<img src="../../../_images/some_image.png">
So there is correct src from the image directive but an incorrect href attribute from the hyperlink.
Questions:
is there any way to generate links in the way that image directive does it? I mean relative to the document.
is there any other (built in) way to have "thumbnail-> click -> big image" behaviour?
Simply use the scale option:
.. image:: large_image.png
:scale: 20%
When the scaled image is clicked on, the full image loads in its own window. So this doesn't increase the image size on the page, but that would be messy anyway.
When you use the image directive from within Sphinx, Sphinx does some special handling to find the image file and copy it into your project (like your _images directory), and then renders the HTML to point to that place.
But the target option just takes a URL as a parameter. It knows nothing about your Sphinx project, or how your images are laid out, and does not attempt to guess.
If you want to have it point to a larger version of the same file, you will likely need to do some manual steps (like maybe copying the file to a specific location), or maybe provide a relative URL to the large file, rather than the absolute URL you have in your example.
If you want to go a completely different way, you could also try overriding and modifying the HTML templates for your project to add some JavaScript to get the click-to-larger-image effect you want.
Looks like there is a Sphinx extension that does this now, and quite nicely at that, sphinxcontrib-fancybox 0.3.2. Install with pip, add it to your extensions in conf.py, and use the fancybox directive:
.. fancybox:: images/image.png
Relative links seem to work. For the Mapserver docs setup, if an image is placed in the images directory, a relative link like in the following code works in my local build. Here is an example using figure (the underscore ("_") before "images" in the target link is necessary):
.. figure:: ../../images/carto-elements.png
:height: 400
:width: 600
:align: center
:target: ../../_images/symcon-overlay.png

Resources