Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alt option for image() #559

Merged
merged 6 commits into from
Apr 13, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions macros/PGbasicmacros.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2908,12 +2908,7 @@ sub row {
=head2 Macros for displaying static images

Usage:
$string = image($image, width => 100, height => 100, tex_size => 800)
$string = image($image, width => 100, height => 100, extra_html_tags => 'align="middle"', tex_size => 800)
$string = image([$image1, $image2], width => 100, height => 100, tex_size => 800)
Alex-Jordan marked this conversation as resolved.
Show resolved Hide resolved
$string = caption($string);
$string = imageRow([$image1, $image2 ], [$caption1, $caption2]);
# produces a complete table with rows of pictures.
$string = image($image, width => 100, height => 100, tex_size => 800, alt => 'alt text', extra_html_tags => 'style="border:solid black 1pt"');

=cut

Expand All @@ -2929,6 +2924,8 @@ sub image {
width => 100,
height => '',
tex_size => 800,
# default value for alt is undef, since an empty string is the explicit indicator of a decorative image
alt => undef,
extra_html_tags => '',
);
# handle options
Expand All @@ -2944,6 +2941,7 @@ sub image {
my $width = $out_options{width};
my $height = $out_options{height};
my $tex_size = $out_options{tex_size};
my $alt = $out_options{alt};
my $width_ratio = $tex_size*(.001);
my @image_list = ();

Expand All @@ -2952,6 +2950,7 @@ sub image {
my $height_attrib = '';
$height_attrib = qq{height = "$height"} if ($height);

# if image() is being called to support the legacy imageRow(), its argument may be an array reference
if (ref($image_ref) =~ /ARRAY/ ) {
@image_list = @{$image_ref};
} else {
Expand Down Expand Up @@ -2994,15 +2993,22 @@ sub image {
|| $displayMode eq 'HTML_asciimath'
|| $displayMode eq 'HTML_LaTeXMathML'
|| $displayMode eq 'HTML_img') {
$out = qq!<IMG SRC="$imageURL" class="image-view-elt" tabindex="0" role="button" WIDTH="$width" $height_attrib $out_options{extra_html_tags}>!
my $altattrib = '';
if (defined $alt) {$altattrib = 'alt="' . encode_pg_and_html($alt) . '"'};
$out = qq!<IMG SRC="$imageURL" class="image-view-elt" tabindex="0" role="button" WIDTH="$width" $height_attrib $out_options{extra_html_tags} $altattrib>!
drgrice1 marked this conversation as resolved.
Show resolved Hide resolved
} elsif ($displayMode eq 'PTX') {
my $ptxwidth = 100*$width/600;
$out = qq!<image width="$ptxwidth%" source="$imageURL" />!
if (defined $alt) {
$out = qq!<image width="$ptxwidth%" source="$imageURL"><description>$alt</description></image>!
} else {
$out = qq!<image width="$ptxwidth%" source="$imageURL" />!
}
} else {
$out = "Error: PGbasicmacros: image: Unknown displayMode: $displayMode.\n";
}
push(@output_list, $out);
}
# if image() is being called to support the legacy imageRow(), wantarray is true
return wantarray ? @output_list : $output_list[0];
}

Expand Down