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

[WIP] Accepting "format" as a query parameter #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

jaxxibae
Copy link
Member

@jaxxibae jaxxibae commented Jul 6, 2021

When ?format=<png|svg> is present, it'll automatically convert the image to one of the two formats.
If not specified, will return a SVG image.

@jaxxibae
Copy link
Member Author

jaxxibae commented Jul 6, 2021

Known Bug: images using ?format=png aren't rendering the server icon.

image

@jaxxibae jaxxibae added enhancement New feature or request help wanted Extra attention is needed labels Jul 6, 2021
@jaxxibae jaxxibae self-assigned this Jul 6, 2021
@jaxxibae
Copy link
Member Author

jaxxibae commented Jul 6, 2021

@pedrofracassi help

res.setHeader('Content-Type', 'image/svg+xml')
res.send(inviteSVG)

switch (req.query.format.toLowerCase()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause the request to fail if format is not passed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One could fix the other issue as well (don't recall the #) to handle failed requests gracefully

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've just realized the fuck up, don't mind me. Will fix it soon.

@pedrofracassi
Copy link
Member

How are we placing the icon in the image? Does this problem have something to do with sharp not being able to fetch the icon? Do we use base64?

@jaxxibae
Copy link
Member Author

jaxxibae commented Jul 11, 2021

I think sharp isn't converting that <image> tag that's embedded in the SVG variant, we'd have to figure it out.

@pedrofracassi
Copy link
Member

Maybe try this? https://stackoverflow.com/questions/58408753/svg-as-svgs-image-tag-not-working-while-using-with-sharp

@Galaxy-Coding
Copy link

Any updates on this PR? Maybe the make an issue in the sharp Github.

@jaxxibae
Copy link
Member Author

jaxxibae commented Jul 23, 2021

No need to send them an issue, I just haven't got the time yet to pick this back up, I'll probably pick it up today.

EDIT: Thanks @pedrofracassi for the suggestion, I'll test it when I can.

@jaxxibae
Copy link
Member Author

Also @almeidx when format isn't specified, should it default to SVG?

@almeidx
Copy link
Member

almeidx commented Jul 23, 2021

Also @almeidx when format isn't specified, should it default to SVG?

To avoid breaking changes to the API, yes

@jaxxibae
Copy link
Member Author

@pedrofracassi Your suggestion didn't work. I wasn't able to convert the jpeg/gif file which is our guild icon inside the SVG, w/o using other libs, and I don't want to add more dependencies to this project.

@ghost
Copy link

ghost commented Mar 3, 2023

You guys could always use ReSVG v2 added the ability to render images from external links

@ghost
Copy link

ghost commented Mar 4, 2023

Tested ReSVG and it did work

@Vendicated
Copy link

Known Bug: images using ?format=png aren't rendering the server icon.

image

mostly likely due to #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add an option to convert svg to png in url parameters
5 participants