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

allow omission of height from image subroutine and preserve aspect ratio #316

Merged
merged 1 commit into from
Aug 2, 2017

Conversation

Alex-Jordan
Copy link
Contributor

Prior to this commit, when calling the image() subroutine, omitting a height specification causes a default of 100 (px) to be used in HTML output. This changes the behavior so that when a height is not specified, it is not specified in the HTML IMG tag either. So the specified width (or the default width of 100) will be combined with the image's actual aspect ratio by the browser to define the width that we see.

I tested with:

$g = init_graph(-2,-2,2,2,axes=>[0,0],size=>[300,200]);
add_functions($g, "-x for x in <-2,2> " .
    "using color:blue and weight:2");

BEGIN_TEXT
\{image(insertGraph($g))\}

\{image("some-gif.gif")\}

\{image("some-jpg.jpg")\}

END_TEXT

where the first image is a dynamically created png, and the second two images were uploaded adjacent to the .pg test file. Best to use images that do not have 1:1 aspect ratios. Then play around with adding width=>some-number and see if the width is respected and the aspect ratio is maintained. Then also specify height and see if that is respected.

Test across browsers.

No need to test hard copy output because the code doesn't touch that.

This change in behavior should not affect OPL problems because they should have been specifying a height up to now. The only way this would change OPL problems is if there is a problem that wanted the 100 px height and was obtaining it by letting the default take hold instead of explicitly asking for 100px. And even then, there will be no bad effect unless the problem author intentionally wanted a bad aspect ratio.

The purpose of this commit is to allow authors to only specify a width when using image() and not worry about height.

@mgage mgage changed the title allow omission of width from image subroutine and preserve aspect ratio allow omission of height from image subroutine and preserve aspect ratio Jul 25, 2017
@mgage
Copy link
Member

mgage commented Aug 2, 2017

This mostly works as expected. Setting neither height nor width gives a width of 100 and preserves the native aspect ratio of the image. Setting width, without specifying height changes the size of the image preserving the aspect ratio to the specified width. Setting height, without setting width, uses the default size (100) for the width and changes the height -- does not preserve the aspect ratio. (this is with chrome -- some of this stuff may be browser dependent.)

@mgage
Copy link
Member

mgage commented Aug 2, 2017

Seems like it does what is needed for PreTeXt. and doesn't mess with the expected defaults. (The expected defaults were not well defined in any case.)

@mgage mgage merged commit a140ed5 into openwebwork:develop Aug 2, 2017
@Alex-Jordan Alex-Jordan deleted the image-aspect-ratio branch January 4, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants