Difference between revisions of "StaticImages"

From WeBWorK_wiki
Jump to navigation Jump to search
m
(The instructions were obsolete and do not work)
(13 intermediate revisions by 2 users not shown)
Line 2: Line 2:
   
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
<em>This code snippet shows the essential PG code to insert a static (pre-generated) graphic image into a problem. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.</em>
 
  +
<em>The instructions below seem out-of-date. See discussion using [@ ... @]* in https://webwork.maa.org/moodle/mod/forum/discuss.php?d=3287 which works.
  +
  +
OLD:
  +
This code snippet shows the essential PG code to insert a static (pre-generated) graphic image into a problem. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.</em>
 
</p>
 
</p>
 
<p style="text-align:center;">
 
<p style="text-align:center;">
Line 17: Line 20:
 
<pre>
 
<pre>
 
BEGIN_TEXT
 
BEGIN_TEXT
  +
 
\{ image( "imagename.png" ) \}
 
\{ image( "imagename.png" ) \}
   
 
\{ image( "imagename.png", width=>150, height=>150,
 
\{ image( "imagename.png", width=>150, height=>150,
tex_size=>250, extra_html_tags=>'alt="Graph of a function."' ) \}
+
tex_size=>700, extra_html_tags=>'alt="Graph of a function."' ) \}
  +
   
 
END_TEXT
 
END_TEXT
Line 26: Line 30:
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
Here it's easy: we just use the <code>image</code> macro in the text section of the problem to include the image. The images to be included should be GIF or PNG files. PNG files are recommended since they generally look better when rescaled. In order for PDF hardcopy generation to work properly, the names of image files must have only one period in them (imagename.png works but image.name.png does not).
+
Here it's easy: we just use the <code>image</code> macro in the text section of the problem to include the image. The images to be included should be GIF or PNG or JPG files. PNG files are recommended since they generally look better when rescaled. In order for PDF hardcopy generation to work properly, the names of image files must have only one period in them (imagename.png works but image.name.png does not). PDF files will work on hardcopy but do not immediately render in the browser without first clicking on the image box. In this case, the use of alternate text is needed.
 
</p>
 
</p>
 
<p>
 
<p>
For each PG problem with static images, you should put both the PG file and the image files into their own separate subdirectory. This subdirectory should be located somewhere under the course <code>templates</code> directory and have the same root name as the PG file. For example, if you have a PG file called <code>Contour-plots.pg</code> which uses static graphic files <code>Contour-plot-01.gif</code> and <code>Contour-plot-02.gif</code>, you should create a subdirectory somewhere under the course <code>templates</code> directory called <code>Contour-plots</code> and put the PG file and all the GIF files in it. Putting a PG file and all of its graphics files into their own separate subdirectory like this makes it easier to find the graphics files that go with each PG file, thereby making the problem easier to maintain. The library browser in WeBWorK is configured to recognize that when a subdirectory has the same name as the root name of the only PG file in that subdirectory, the subdirectory and PG file should be treated as a single entity for the purpose of browsing the library via directories.
+
For each PG problem with static images, you should put both the PG file and the image files into their own separate subdirectory. This subdirectory should be located somewhere under the course <code>templates</code> directory and have the same root name as the PG file. For example, if you have a PG file called <code>Contour-plots.pg</code> which uses static graphic files <code>Contour-plot-01.gif</code> and <code>Contour-plot-02.gif</code>, you should create a subdirectory somewhere under the course <code>templates</code> directory called <code>Contour-plots</code> and put the PG file and all the GIF files in it. Putting a PG file and all of its graphics files into their own separate subdirectory like this makes it easier to find the graphics files that go with each PG file, thereby making the problem easier to maintain. The reason for having the subdirectory and the root name of the PG file be the same is as follows. When the library is browsed via directories, the library browser in WeBWorK is configured to recognize that when a subdirectory has the same name as the root name of the only PG file in that subdirectory, the subdirectory and PG file should be treated as a single entity.
 
</p>
 
</p>
 
<p>
 
<p>
We can, of course, include options such as specifying the <code>tex_size</code>, etc., in this call, as shown in the [[DynamicImages|including dynamic images]] code snippet.
+
We should always, of course, include options such as specifying the <code>tex_size</code>, etc., in this call, as shown in the [[DynamicImages|including dynamic images]] code snippet. Taking the <code>tex_size => "667"</code> and dividing by 10 results in the percentage of the available space used by the graphic -- in this case 66.7 percent. Usually the available space is constrained by the width of one column of a two-column printed page.
 
</p>
 
</p>
 
<p>
 
<p>

Revision as of 02:16, 27 October 2020

Static Graphic Images: PG Code Snippet

The instructions below seem out-of-date. See discussion using [@ ... @]* in https://webwork.maa.org/moodle/mod/forum/discuss.php?d=3287 which works. OLD: This code snippet shows the essential PG code to insert a static (pre-generated) graphic image into a problem. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

Problem Techniques Index

PG problem file Explanation
BEGIN_TEXT

\{ image( "imagename.png" ) \}

\{ image( "imagename.png", width=>150, height=>150,  
tex_size=>700, extra_html_tags=>'alt="Graph of a function."' ) \}


END_TEXT

Here it's easy: we just use the image macro in the text section of the problem to include the image. The images to be included should be GIF or PNG or JPG files. PNG files are recommended since they generally look better when rescaled. In order for PDF hardcopy generation to work properly, the names of image files must have only one period in them (imagename.png works but image.name.png does not). PDF files will work on hardcopy but do not immediately render in the browser without first clicking on the image box. In this case, the use of alternate text is needed.

For each PG problem with static images, you should put both the PG file and the image files into their own separate subdirectory. This subdirectory should be located somewhere under the course templates directory and have the same root name as the PG file. For example, if you have a PG file called Contour-plots.pg which uses static graphic files Contour-plot-01.gif and Contour-plot-02.gif, you should create a subdirectory somewhere under the course templates directory called Contour-plots and put the PG file and all the GIF files in it. Putting a PG file and all of its graphics files into their own separate subdirectory like this makes it easier to find the graphics files that go with each PG file, thereby making the problem easier to maintain. The reason for having the subdirectory and the root name of the PG file be the same is as follows. When the library is browsed via directories, the library browser in WeBWorK is configured to recognize that when a subdirectory has the same name as the root name of the only PG file in that subdirectory, the subdirectory and PG file should be treated as a single entity.

We should always, of course, include options such as specifying the tex_size, etc., in this call, as shown in the including dynamic images code snippet. Taking the tex_size => "667" and dividing by 10 results in the percentage of the available space used by the graphic -- in this case 66.7 percent. Usually the available space is constrained by the width of one column of a two-column printed page.

(When the alias() command in dangerousMacros.pl is rewritten in the future, support for JPG, PDF, and SWF files should become available.)

Problem Techniques Index