is it possible with php (or js/css) to change the background from an SVG (by using an normal image) and convert it to an png?
Example
Related
Is it possible to create a temp file server side for viewing an image?
I've some images & they're displayed from server but I want to have them watermarked... Found out about the Imagick Class, used composite... It can be viewed when sent as header but I need it somehow visible for the tag.
I don't want to uses 'write image' & create a new image from the composited image. I'm trying to use it as client Side thing (I'm not familiar with JS... Yes, I'll look into it but need an alternative till then).
Another alternative that I'm aware of is I should control that WHILE uploading the images but I've already uploaded quite a few so...
Any help appreciated!
Have you tried using the function that generates your image as a src attribute for the <img /> tag?
I don't know exactly how your code is, but I am thinking the end result could be something like:
<img src="data:image/jpeg;base64,<?php echo base64_encode($image_headers); ?>">
You basically output the headers inside the image src as a base64 encoded string.
What you should keep in mind is that you should adjust the image/jpeg type to the corresponding type of your image.
For example:
For JPG, JPEG files it would be image/jpeg
For PNG files it would be image/png
For WEBP files it would be image/webp
And of course the encoded string should be an image of the corresponding format.
So I have this problem where I'm receiving a webp,base64 image format from an api, The image does not show in ios devices but it appears in Android. So is there a solution for those who use expo and want to display webp images on ios?
And I can take another solution if it works in php since that is what I'm using as a backend.
an example of the returned string of the image
https://i.stack.imgur.com/k1yHv.png
Normally webp images are not compatible with Safari. You can check the compatibility for webp here.
What you would need to do is maybe use a service that converts the image to a working format, be it jpeg or png and use a <picture> tag. This is just an example of how to use the tag.
<picture>
<source srcset="images/logo#1x.webp" type="image/webp">
<source srcset="images/logo#1x.png" type="image/png">
<img src="images/logo#1x.png" alt="Logo">
</picture>
UPDATE
The above example was just to show you how to use the picture tag with different types of images.
As for the base64 images you could do something like this:
<picture>
<source srcset="data:image/webp;base64,UklGRlAIAABXRUJQVlA4IEQIAADQJACdASp+AH4APrFInUmnJCMhMXX8qOAWCWYAzb8cfTdXBy5F/Zz8xxC6HLaHpz3DPmV84d5OXdQ/aP854a+OL4BubX158GjTsd4ATr92rmvq3p43/Y82n1kj6wv3/Vk3gOKXh/1H/Z+6V9sps7nNgfOA82ktkJO4nWXR/P0q1RbEZE/vsMgdJc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jAipiUiubbfiwwrsIiY4+03mL83Le9UEZI9mWVxzqlgCtmnsQj6OziYYHe7ZUZUNYiwj8aQ80Alwl86v0Qm3jGbV87zz1zD5mY0lSAvgFRiertd+d9ApQCAVSN38ctxv0j6QnqVf+FKQgky0QjkRAq+Sj3VmtHbKYzst4S1v8SEdYg+nRQlavgCn7P2ZROy6FKFB8suTT2uqwBn2YO65/U91t4qZy+joHNmcU2P5nXN8xpAGhofD4VyM+rg2TCHfidGDYMy8nIzy+wqsNSs77qJC5eYUgkj9B1vb+wpcEdGN64HxSNeGtqtNb2sgf5j92YiUZV/FlOl34+mhYOS74maW79xUwu57G7oIAbIpPHy7aXTPjDx5atVnIxglURPcRxySbfmYdANkleH5sQYUoEXGlCfK4BTzlmzv7koFsfPZcSsjf1AfEAFGe9t5bn/qb/rnbB5jqg9pcDyDQhnQxziha2oZ5Bdndh57b4zOGPEMmr+zRCdg+EoAAAA" type="image/webp">
<source srcset="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2NjIpLCBxdWFsaXR5ID0gNjAK/9sAQwANCQoLCggNCwoLDg4NDxMgFRMSEhMnHB4XIC4pMTAuKS0sMzpKPjM2RjcsLUBXQUZMTlJTUjI+WmFaUGBKUVJP/9sAQwEODg4TERMmFRUmTzUtNU9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09P/8AAEQgAfgB+AwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsf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djjPiZqYisYNNRvnmbzHx/dHT9f5VtfD/AE06f4aidxiW6Pmt9Dwv6fzrgrSOfxl4wLyAiFm3P6JGO39Pxr2FEWNFRFCqowAOwr6GjT9lTUepzN80rjq89+IvhpnJ1qxT5h/x8Ko/8e/xr0KkZVdSrgMpGCCOCKtOwNXOI8D+KV1CBdOvpALuMYRj/wAtF/xrsa818YeEJ9LnOqaOG+zht7Imd0J9R7fyrS8LeOIrlVs9YYRTDhZzwr/73oa87F4T7dP7i4VOjO4opFYMAVIIPQilrzDcKKKKACiiigAooqC6u7ezt2nupkiiXqzHFNJt2QtiZmCqSSABySe1eYeNPEb6zdrpWmEvbq4BK9ZX9vak8TeL7jWZDp2krItu525A+eX29h7V0vgrweNKVdQ1FQ16w+ROoiH+NethMJ7P357mE582iNLwb4eXQdLAlAN5Nhpm9PRfwroaKK7SQooooAQgEYIyDXEeJvAEF8z3WkFbe4PLRHhG+np/Ku4ooTsDVzxy01rxB4Un+y3KP5a/8sZwSuP9k/4V12meP9JugFvBJaSd9w3L+Y/wrrruztr6Ew3kEc0Z/hdc1yepfDrSbgl7KWWzY9h86/kef1rKrhqVTWS1BOUdjobXU7C8ANreQTZ7JICfyq0DnvXlep+Ab+xyyXlvIo6Z3Kf5GsCSO+tHMYumGP7kjYrleWrpItVn1R7mWAGSQPrWdea/pNkD9p1C3Uj+EPuP5CvIrfTb7UXC/aFJP/PR2/wrptO+G11cqHudRhjTv5aFj+uKccuivikL2z6Ivat8RbeMFNLtmlboJJflX8uprnYbPxF4yuhI5dogf9Y/yxJ9P/rV3ul+BdE08h3ha6lH8UxyP++RxXSoqooRFCqBgADAFdVOjTpfAiW3LcwPDfhKw0FBIB594R80zDp7KO1dDRRWgBRRRQB//9k=">
</picture>
Another option could be to use Modernizr to detect if the client's browser can use webp. You can check and build a Modernizr specifically for webp detection. Check it here.
What you would need to do if you have control over how the images are created/uploaded is to have a jpg/png and a webp version, and just use the corresponding versions as necessary. You do need to have both, because as I said before webp is still not compatible with every browser.
If you run the snippet you'll see that if you try to download the image it will use the webp version. If you open it from Safari it would download the jpg version.
UPDATE 2: Image conversion
As for the image conversion, what you could do is either make an image generating function that receives a webp image as a parameter and returns a jpg image.
Since you receive the image in a base64 format, you could use this topic to save the image on your server, but in a .webp format in your case. Afterwards you could use the imagecreatefromwebp() function to create a new image. Check the example at the end of that page. It converts a webp image to a jpeg.
From what I see you could do something like:
Get your API call that contains information on the image.
Check if your image exists on your server (the ideal is to create a specific folder and use the same image name).
If it exists, you return the path to the image.
If it doesn't exist, you create a .webp file from the base64 data. Then you convert it to a .jpg or a .png file depending on your needs.
You use the local image. That might also speed up your calls.
I'm trying to upload images in Silverstripe and have them treated as images rather than a document link.
I've added SVG to the allowed filetypes and can upload an SVG file but when I hit insert the editor inserts the tag as
somefile.svg
I would like to treat SVG as any other image format where inserting will insert the tag as a regular image
<img src="/assets/uploads/somefile.svg">
What is the best way to achieve this?
After debugging around HtmlEditorField.js, I found that the issue for SVGs not displaying was that the "Insert Media" screen's upload field does not consider an SVG as an image. (I originally thought the problem was TinyMCE but that wasn't the case)
I knew that the File class has a static property called app_categories which contains things like all the extensions SS thinks are images. By default, SVG is not in this list.
In Silverstripe 3.1, if you specify the following, it will add SVG to the "image" category:
$categories = File::config()->app_categories;
$categories['image'][] = 'svg';
File::config()->app_categories = $categories;
Alternatively as a YAML config:
File:
app_categories:
image:
- svg
That simple change was enough for the file upload on the "Insert Media" screen to correctly treat a SVG as an image which in turn triggered the right entwine function to use the <img> tag rather than an anchor.
While this method solves your specific issue, there could be side effects throughout other parts in Silverstripe for adding SVG to the image app category.
One additional thing, I needed to update my .htaccess file in my assets folder for it to allow viewing of SVG files otherwise I got a 403 Forbidden error.
in SS3 just use this in your config.yml:
File:
allowed_extensions:
- svg
Image:
allowed_extensions:
- svg
I've written a SilverStripe module to do exactly that (treat SVG as image instead of file): https://github.com/micschk/silverstripe-svg-images/
See the README for general pointers on how to set up SVG-as-image if you don't want to require the module.
I have javascript code that generates svg image tags on the fly when a person lands on one of the pages. Im using the d3 library to help make the image. The only problem is that d3 is not fully IE compatible and I would want to generate a .png, jpg, gif or any other image file based on the svg file. Is there a known way to do this?
The server side code is PHP based, and we use node.js, and render.js for a lot of the dynamic content.
I'm using ImageMagick to convert SVG images to PNG images.
This works pretty well.
A quick example of how to do this:
exec('/usr/bin/convert /path/to/image.svg /path/to/output_image.png');
I'm using this with great success for processing QR codes made with libqrencode to different sizes and colors.
Firstly you need to use a DOM implementation on server side as you want to get svg which is rendered on client side.For this we use jsdom with node.js.
Using this you can render D3 on server side and get svg on server then convert it to any format you like.
Here is the link on how to that.
Once you got SVG and PNG then by using modernizer.js
1)Check compatibility of browser using Modernizr.
2)Then load SVG or PNG basing upon on the compatibility.
Example (JS solution):
if (!Modernizr.svg) {
$("#logo").css("background-image", "url(fallback.png)");
}
Example (CSS solution):
.no-svg #logo { background-image: url(fallback.png); }
Our printer is set up to handle PPML files.
We would like to include some SVG charts to be printed. SVG Charts are built with PHP and YUI3.
How to incorporate SVG charts into PPML files?
How to include YUI3 charts into PPML?
In your PPML file, I believe you should be able to add the tag below:
<SOURCE Dimensions="thewidthinpixels theheightinpixels" Format="image/svg+xml">
<EXTERNAL_DATA Src="yoursvgfilepath.svg" />
</SOURCE>
Here's an example PPML file (although it doesn't include an SVG example):
Example PPML code
And, if you wanted to just copy and paste the svg in, it appears you can embed it as internal data, too:
W3C reference regarding use of SVG in PPML