Skip to content

[4.3] Media Manager support for svg images + set natural{width/height}#39586

Merged
obuisard merged 23 commits intojoomla:4.3-devfrom
dgrammatiko:4.3-dev-svg-size
Jan 16, 2023
Merged

[4.3] Media Manager support for svg images + set natural{width/height}#39586
obuisard merged 23 commits intojoomla:4.3-devfrom
dgrammatiko:4.3-dev-svg-size

Conversation

@dgrammatiko
Copy link
Copy Markdown
Contributor

@dgrammatiko dgrammatiko commented Jan 10, 2023

Pull Request for Issue #39571, #39538, #39543 . Complimentary to #39574 Previous attempt: #38722

Summary of Changes

  • Fixes the wrong mime type for svg
  • adds a load event to grab the naturalWidth/naturalHeight

In pictures

Screenshot 2023-01-10 at 09 18 40
Screenshot 2023-01-10 at 09 18 51
Screenshot 2023-01-10 at 09 19 02

Testing Instructions

  • First add svg to the image extensions, allowed extensions and image/svg+xml to the allowed mime types
  • Goto Caasiopeia styles and select a new logo
  • Upload an svg
  • Select the svg and check that the url has width/height at the end

Actual result BEFORE applying this Pull Request

Expected result AFTER applying this Pull Request

Screenshot 2023-01-10 at 09 19 27

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@joomla-cms-bot joomla-cms-bot added NPM Resource Changed This Pull Request can't be tested by Patchtester PR-4.3-dev labels Jan 10, 2023
@viocassel
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on ed67f35

👌


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39586.

@dgrammatiko dgrammatiko changed the title [4.3] Fix svg width/height [4.3] Media Manager support for svg images + set natural{width/height} Jan 10, 2023
…ation-types.es6.js

Co-authored-by: Quy <quy@nomonkeybiz.com>
@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

Added settings, but getting "Unable to upload file." error in Media Manager. I have to investigate why. Added manually for now.

Following are issues:

No image on the frontend.

No preview.
39586-preview

Width/Height = 0
39586-select

No dimensions.
39586-info

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

dgrammatiko commented Jan 10, 2023

Added to the settings, but I am getting "Unable to upload file." error. I have to investigate why. Added manually for now.

Is it a valid svg file?
Can you share it? (eg zip it and uploaded here)
Can you clean the svg using: https://jakearchibald.github.io/svgomg/ and try again?

these are the options on my test site:

{
"Allowed Extensions" : "svg,bmp,gif,jpg,jpeg,png,webp,ico,mp3,m4a,mp4a,ogg,mp4,mp4v,mpeg,mov,odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,csv",
"Legal Image Extensions (File Types)": "svg,bmp,gif,jpg,png,jpeg,webp",
"Legal MIME Types": "image/svg+xml,image/jpeg,image/gif,image/png,image/bmp,image/webp,audio/ogg,audio/mpeg,audio/mp4,video/mp4,video/webm,video/mpeg,video/quicktime,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip"
}

Screenshot 2023-01-10 at 18 46 23

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

My settings are the same. Here is the cleaned logo using the service which I can now upload but the other issues remain.

clean_logo.zip

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

In the browser console, after selecting a SVG file for the logo.

39586-select-svg

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

dgrammatiko commented Jan 10, 2023

Oh, I think it's the + on your folder that messes up the apache, do you remember that issue?

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

I do remember now, but I have the same issues under joomla-cms-4.3-dev without +.

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

In the browser console, after selecting a SVG file for the logo.

Inspecting more carefully the reported URL is wrong, it shouldn't have the /administrator part. This comes from the Form Field Media and now I have to debug this, but to do so I need to reproduce the error...

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

@Quy can you do something, got to the page where the console error happen, open the browser inspector and paste in the console this Joomla.getOptions('system.paths') and report back what is the value returned. Thanks

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

Object { root: "/joomla-cms-4.3-dev", rootFull: "http://localhost/joomla-cms-4.3-dev/", base: "/joomla-cms-4.3-dev/administrator", baseFull: "http://localhost/joomla-cms-4.3-dev/administrator/" }

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

Thanks, so the values are correct...

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

This is only happening with SVG files.

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

This could be why width/height=0 due to not finding the image when selecting a SVG file.
images/clean_logo.svg#joomlaImage://local-images/clean_logo.svg?width=0&height=0

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

This could be why width/height=0 due to not finding the image when selecting a SVG file.

Yes, but the root is not actually in the Form Field Media, but probably in the PHP code of either the filesystem or the MediaHelper, I guess for some reason the followin conditional is wrong on your machine: https://github.com/joomla/joomla-cms/pull/39586/files#diff-b9cf1b73ab2438daa98290f2c650099e320527df061d94e31763982e9743dacdR116

Could you patch that line to:

        if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'svg' && self::isValidSvg($file, false)) {

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 10, 2023

No go :(

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 13, 2023

I have tested this item ✅ successfully on be07515

THANK YOU!


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39586.

@obuisard
Copy link
Copy Markdown
Contributor

obuisard commented Jan 14, 2023

I have been doing some testing and I would like to know if someone got into this one:

on my tests, everything works great (yeah!) on my php 8 environments. However, uploads fail and thumbnails don't show in php 7.4 in the media manager. I will retry with the full package (I just tried the PR's update package) and see if I get the same issues.

Nevertheless, I wanted to mention it and see if others ran into the same problems. I don't have any errors in logs or console errors either.

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

dgrammatiko commented Jan 14, 2023

However, uploads fail and thumbnails don't show in php 7.4 in the media manager

Are those svg files or any image?
Also couple of things: what are the contents of mime.types of your 7.4 apache? In particular is there an uncommented line with svg image/svg+xml?
But this might come from the Sanitizer, which is a bug revealed by this PR and probably worth a new issue

@obuisard
Copy link
Copy Markdown
Contributor

obuisard commented Jan 14, 2023

However, uploads fail and thumbnails don't show in php 7.4 in the media manager

Are those svg files or any image?

Only SVG images.

Also couple of things: what are the contents of mime.types of your 7.4 apache? In particular is there an uncommented line with svg image/svg+xml?

image/svg+xml is uncommented in mime.types.

Note that I use the same Apache for php 7 and 8 tests.

I will try in another environment (tried initially in Wampserver).

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

@obuisard set a break point here: https://github.com/joomla/joomla-cms/pull/39586/files#diff-b9cf1b73ab2438daa98290f2c650099e320527df061d94e31763982e9743dacdR514 do you get any errors or the sanitisation completes correctly?

@obuisard
Copy link
Copy Markdown
Contributor

@obuisard set a break point here: https://github.com/joomla/joomla-cms/pull/39586/files#diff-b9cf1b73ab2438daa98290f2c650099e320527df061d94e31763982e9743dacdR514 do you get any errors or the sanitisation completes correctly?

It does not even get there.
The only thing I can see is that, when I drag and drop a clean SVG file file under Apache with PHP 8, I get
POST /administrator/index.php?option=com_media&format=json&mediatypes=0,1,2,3&task=api.files&path=local-images:/ HTTP/1.1" 200
But under PHP 7, I get
POST /administrator/index.php?option=com_media&format=json&mediatypes=0,1,2,3&task=api.files&path=local-images:/ HTTP/1.1" 403

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

@obuisard then that's another issue

@obuisard
Copy link
Copy Markdown
Contributor

@obuisard then that's another issue

Agree, just can't figure out what it is. We need someone else to test your PR. Reaching out.

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

@obuisard can you email me you php 7.4 ini file?

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

@obuisard fwiw the issue is not related as it's (probably) coming from

if (!$this->app->getIdentity()->authorise('core.create', 'com_media')) {
throw new \Exception(Text::_('JLIB_APPLICATION_ERROR_CREATE_RECORD_NOT_PERMITTED'), 403);
}
which seems a invalid token or something similar...

@sdwjoomla
Copy link
Copy Markdown
Contributor

I have tested this item 🔴 unsuccessfully on be07515

PHP 7.4.21
Unable to upload SVG.
Content > Media > Upload > selected image > "Upload button"
Outcome: message "An error occurred." and image didn't upload


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39586.

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

@sdwjoomla can you try uploading the same svg on the 4.3-dev branch (not this pr)?
if it’s failing there then you have another issue that this pr revealed…

@sdwjoomla
Copy link
Copy Markdown
Contributor

sdwjoomla commented Jan 16, 2023

@dgrammatiko
Retesting ... actions taken and the outcome listed below ... all testing done in PHP 7.4 except where noted.

Downloaded Joomla_4.3.0-alpha3-dev+pr.39586-Development-Full_Package.zip
Image uploaded. Media manager Info does not include dimensions when on PHP7.4. but does on PHP8.0.

Clicking the vertical three dot menu and selecting Preview displays the image correctly. Thumbnail does not display.
Selecting the image as logo for the template worked and shows the correct dimensions.

Tried upload a new SVG, no change to settings, received error "unable to upload file"
Checked settings and file sizes - no issues with them.

In Cassiopeia, changed logo back to a PNG, saved, then changed back to SVG, the dimensions displayed incorrectly as 0 width and 0 height.

Manually added SVG to the images folder on the server, thumbnail displays, selected the image in the media manager and clicked the 'i' icon/link, the dimensions display correctly
Selected the new image as a logo, the dimensions display correctly as images/SimplePurpleCarTopView.svg#joomlaImage://local-images/SimplePurpleCarTopView.svg?width=148&height=73

Downloaded Joomla_4.3.0-alpha3-dev-Development-Full_Package.zip
Used https://ci.joomla.org/artifacts/joomla/joomla-cms/4.3-dev/39586/downloads/60858/pr_list.xml to apply PR
Tried to upload a SVG, no change to settings, received error "unable to upload file"
Checked settings and file sizes - no issues with them.
Manually added SVG to the images folder on the server, thumbnail displays, selected the image in the media manager and clicked the 'i' icon/link, the dimensions display correctly
Selected the new image as a logo, the dimensions display correctly as images/cyberscooty-kids_smiling.svg#joomlaImage://local-images/cyberscooty-kids_smiling.svg?width=165&height=150

Please note there is a typo in the testing instructions, image\svg+xml, should be image/svg+xml

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

dgrammatiko commented Jan 16, 2023

@obuisard @sdwjoomla fwiw both 4.2 and 4.3 failed to upload svg with 7.4. Anyways, the problem is the returning mime type, with php 8+ we get application/octet-stream but with php 7 we get image/svg which is not valid.
This should be fixed now.
Could you check, retest?

@Quy sorry can we have one more retest here?

Thanks

@obuisard
Copy link
Copy Markdown
Contributor

Your last changes fixed everything on my test sites. Thumbs up for your PR, Dimitris @dgrammatiko and help in figuring out what was wrong on our tests.

@obuisard
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on dfcf205


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39586.

1 similar comment
@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 16, 2023

I have tested this item ✅ successfully on dfcf205


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39586.

@Quy
Copy link
Copy Markdown
Contributor

Quy commented Jan 16, 2023

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39586.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jan 16, 2023
@obuisard obuisard added this to the Joomla! 4.3.0 milestone Jan 16, 2023
@obuisard obuisard merged commit 31758bb into joomla:4.3-dev Jan 16, 2023
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jan 16, 2023
@obuisard
Copy link
Copy Markdown
Contributor

Thank you Dimitris @dgrammatiko for this PR!

@dgrammatiko
Copy link
Copy Markdown
Contributor Author

@Quy @obuisard @sdwjoomla thanks for the tests
@crystalenka thanks for the preview css

@SniperSister @HLeithner please consider using a composer package for the mime types

@dgrammatiko dgrammatiko deleted the 4.3-dev-svg-size branch January 16, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

NPM Resource Changed This Pull Request can't be tested by Patchtester

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants