Modifying Image using PHP and sending it to browser - php

I would appreciate your thoughts on this method.
I have a page that uploads a pic given by user and displays it after saving it in a database now that's very simple so, I wanted users to be able to modify these images as they wish, hence I decided to add filters to these images using php. Now before these images are uploaded to the database I want the user to see a preview of what the image looked like after adding the filter.
The solution I came up was to send the image to php file using a form and AJAX using POST, do all necessary checks if file was safe. create a new image and add filter and then convert it to base 64 and send it back to browser and display it using a DATA URL
something like:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4/8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot">
Is this a good idea or there is something I should worry about?

Base-64 encoding adds about 33% overhead. For this reason, it is usually preferable to serve the image in binary form.
You can do this with a PHP script easily.
header('Content-Type: image/png');
echo $yourImageData;
Then in your HTML:
<img src="yourPHPScript.php?id=12345" />

hello we have a library for that actually, we make use of GD library to be able to achieve the correct image output that we would like to have, you can check more about our image library here.. by the way, our library does not only contain image library.. it has a bunch of useful libraries that you can actually use on your projects and we opensource it
http://eden.openovate.com/documentation/core/images

Related

code on a jpg image generated dynamically

While I was looking for some info, I came across this image on a forum which i didn't understood how it worked. Its a JPG image which actually tells you your ip address and your browser. I think that maybe it was made by modifying htacess and replacing PHP for JPG, and with PHP generating the image dynamically but I'm not sure about it.
Would this be the way that this works?
Here is the image i saw:
http://www.danasoft.com/sig/475388.jpg
Thanks
It is nothing but etching text on image. There are several options to do it. Using PHP see here and Java see here
yes this image is generating dynamically. It collects your info make a string and use some library to generate that image like in Captcha. php has its own library too for this purpose
Click here

string image data in html

I'd like to know if it's possible to assign image data as text to an image in HTML form instead of setting it's "src" property to a file path... i want to do it with PHP!...
i remember seeing something like the following code in some websites' source...
for example:
image data = R6+1u5jwhwf6GOG6X6MpFR/hrlbNA1JcqeByPKDIivcJQa2ePIft0Jqewk4/lLYSy4YU1BXARkvdN7vJxx0vUOJGiU5OiMhMhWrH6s1n3pGK0Sat0mMiUCQX4e4BDU+yD1kB87tI+Xh+WitqNN7FyLysoGlAvsGfZQ2bOo+7+7Bm6K4NMktamfNG9v
in this way... by viewing the source of my webpage... it's not possible to see the address of the images used! just it's data! i think it's more secure! MAYBE!
Thanks!
It is not more secure as the picture has to be created in the browser to be displayed by the user.
What you could do (which won't make it any more "secure"), is to have a PHP script that translates your "data" into an image, see this thread for an idea on how to do this!
I think what you're referring to is Base64 encoded images in HTML.
It's not very portable though, not nearly as much as a standard img tag.
if you have image data you can show image on html page like this <img src="data:image/png;imagedatacodehere" /> , if it has png extension, check this link
Yes, it's possible, no it's not more secure. You're talking about data uris, and since the user's browser has to have the image data in order to display the image, you're still sending the picture to the user. All they have to do is right-click/save as on the displayed and boom, done. Also, the image data is just embedded in base64 format into the page itself, meaning you can trivially cut/paste that base64 string and still steal the image, even if you have all kinds of pointless image protection (e.g. right-click disablers).

Displaying BLOB image with other content

Firstly this is for a simple university project, so time is more important than performance of database etc.
I have a database with images stored in blob files. Now some form outputs data from this database, but i want it to also output the image, along with the text.
I realise there is a bit of code to change headers to image, but then the text wont display, so is there a way to display the image and the text on the same page?
thanks a lot,
It is possible to embed images inside HTML, but you usually do it only if you have a really good reason to. Assuming you do, you write the following code, provided that $BLOB is the binary raw data of the image:
<img src="data:image/jpeg;base64,<?php echo base64_encode($BLOB); ?>"/>
Why not use image tags like normal wherever you need the images to be, and in the src attribute, specify a PHP script along with a get argument (for instance, <img src='image.php?name=something.jpg'>). This script then authenticates the request, accesses the database, sends the appropriate headers, followed by the actual BLOB data.

Resize image using PHP from an external image URL

I'm creating a web app that allows users to specify an image url to display an image along with their submission.
To avoid some potentially large images and odd sizes, i'd like to use PHP to limit/resize the image before it gets output to the browser (I know i could use max-width in CSS but this is unnecessary downloading)
Is this possible?
PHP has a library named GD. It's fairly easy to check the size of an image with the getimagesize() function.
You can find the complete code for it with 2 module/extensions: http://www.fliquidstudios.com/2009/05/07/resizing-images-in-php-with-gd-and-imagick/
a comparison of them can be found here: http://dreamfall.blogspot.com/2008/02/php-benchmarks-gd-vs-imagemagick.html which may be of use if you want optimize features.

How to resize linked images dynamically in PHP?

On my site I have given an option to user to choose thier profile image
Type link of an image
Image is a url link, and first I want it to resize to 400x300 (image's original size doesn't matter), and then display it on my web page.
Something like below:
<img src="http://mywebsite.com/resize.php?image=http://someotherurl.com/upload/image2.jpg&width=400&height=300" />
anyone knows this kind of script, please tell me how to solve this issue.
Thanks
A recent post:
https://stackoverflow.com/questions/1302464/php-image-resize-my-upload-script
has some code and comments that may give you some pointers. Otherwise may I suggest
http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php.
Good luck!
If you have the GD extenstion, you can use imagecopyresampled (the documentation also features some examples). However, if the image to be resized is large and there is a low memory limit on your server, you may run out of memory.
I don't have ready to use source code, but it should look like:
Load image pointed by image parameter into object of ImageMagick (or other graphics library).
Resize it.
Send content to output stream.
Optionally you could:
Check if loaded file is image (plus other validation checks).
Save resized image on disk and serve it from disk next time (if you do it often).
Check docs of you favorite graphics library used in PHP for details.
Good luck!
Use the Class called - class.upload.php.
Find it at: PHP Classes
We use it at all times in many of our work.
The name is deceptive but actually it is an uploader as well as image processor. It has a very big list of functionality for resizing images, adding text to images, converting formats, etc. etc.
There is sample code which shows how to read an Image from server, modify it and finally send it directly to browser without having to create a temp file on server.
HTH

Categories