pharo-project / pharo-website

Other
7 stars 13 forks source link

Extend logo image elements to have a file for scale 2 #65

Closed Rinzwind closed 6 months ago

Rinzwind commented 6 months ago

This pull request extends the <img> elements for the logo on the index page and navigation bar to have a file for scale 2. I used the snippet below to generate the PNG files, it’s based on the one I used in Pharo pull request #16305. Note that the small logo had some padding which the newly generated file doesn’t have. The SVG file could perhaps also just be used directly in place of the PNG files. With Pharo 12 having better ‘Retina display’ support (see Pharo pull request #15647) it would in any case be nice for the website to have that too.

Metacello new
    baseline: 'AthensSVG';
    repository: 'github://pharo-contributions/Athens-SVG/src';
    load.
svgRoot := (Smalltalk at: #AthensSVGConverter) fromURL: 'https://files.pharo.org/media/logo/Pharo%20Logo%20SVG/Pharo_Logo_v3.0.svg'.
flarePath := (svgRoot instVarNamed: 'ids') at: 'flare'.
flarePath fill_opacity: (flarePath fill_opacity * flarePath opacity) asString.
#(('pharo' 471) ('pharo-logo-small' 100)) do: [ :arguments |
    arguments bind: [ :name :width |
        extent := width @ (svgRoot height value * (width / svgRoot width value)) rounded.
        #('' '-2x') keysAndValuesDo: [ :scale :suffix |
            | surface surfaceForm convertedForm |
            surface := AthensCairoSurface extent: extent * scale.
            surface drawDuring: [ :canvas |
                canvas pathTransform scaleBy: surface extent / (svgRoot width value @ svgRoot height value).
                svgRoot renderOn: canvas viewportExtent: surface extent ].
            surfaceForm := surface asForm.
            convertedForm := Form extent: surfaceForm extent depth: 32.
            0 to: convertedForm width do: [ :x |
                0 to: convertedForm height do: [ :y |
                    | color |
                    color := surfaceForm colorAt: x@y.
                    convertedForm colorAt: x@y put:
                        (color alpha > 0 ifTrue: [ color / color alpha ] ifFalse: [ color ]) ] ].
            PNGReadWriter putForm: convertedForm onFileNamed: FileLocator imageDirectory / (name , suffix , '.png') ] ] ]