Make "save image as" link to a different image? - php

I'm trying to protect images with a watermark, but I don't want to display the images on the website with the watermark. I created a php script that dynamically watermarks an image on the fly, but here's what I'd like to do with it:
I'd like for whenever someone right clicks and presses "save as" an image displayed on my website for it link to a different image that is watermarked. Is that possible? Should I go about this another way?
Any response in the right direction is greatly appreciated.
Here's an example: http://fatpita.net/?i=14453
When you save this image, the saved image is watermarked, but the website's image is not... I think they actually just mask the watermark on the website though.
Thanks!

What you are trying to achieve is not possible in a safe way.
If the browser gets the unwatermarked file the user can save that file - maybe not using "save image as" but e.g. through Firefox's "page info dialog which contains a full media list.

You can't do anything that the user can't fake. The site you mentioned doesn't either - the watermark is always there.
Look at the actual source:
<div style="position:relative;width:768px;margin:9px auto 0;">
<a href="http://fatpita.net/?i=4011" id="image">
click on the image for another random funny picture<br>
<img src="images/image (14453).jpg?4011">
</a>
<div id="jpgCover">
</div>
</div>
They are actually covering over the watermark in HTML. It is still there, but there is a div in the way making sure you can't see it.
Remember the user can always remove this watermark by an easy crop.

Related

Enlarge an image when clicking on it, Can click next to see next images

I have this code :
<div class="images_liste_plante_solo">
<div class="image_liste_plante">
<img alt="Hosta - Eternal Flame" src="images/eternal_flame_miniature.jpg"/>
</div>
<div class="image_liste_plante">
<img alt="Hosta - Eternal Flame" src="images/eternal_flame-2_miniature.jpg"/>
</div>
<div class="image_liste_plante">
<img alt="Hosta - Eternal Flame" src="images/eternal_flame-3_miniature.jpg"/>
</div>
</div>
I will have a variable number of pictures like this, because the number of pictures depends of my PHP database. I can also echo out the directory of the fullscreen size picture and can choose what is the max size (if they are enough big to reach it) of all pictures.
So, I will need that when we click on the picture, that it enlarge it with a fullscreen gallery over the page that darken what is behind, a bit like when we want to enlarge pictures in facebook. It will only use the images with a class of "image_list_plante" and it will use my echoed link to the fullscreen image for each images (maybe this link could be echoed in an invisible div). Also, I will echo (in the invisible div) a boolean which decide if you can right click on the picture or not. I will even echo text that will be placed under or over the picture. The invisible div will be inside each "image_liste_plante" divs and after or before the picture. I can put classes to these invisibles divs if needed, etc...
How do I do that ? hard question. I know nothing about JavaScript and jQuery and others... The only things I know, it's HTML/CSS/PHP/PDO.
Do a plugin that I can modify and adapt is already built ? for the moment, I will only put a link to a .jpg file on the pictures.... but it can't stay like this too long.
*Will need to work in IE7 and other browsers too.
Finally, i used a plugin called "colorbox". It opens an iframe over the page according to it's link. The page in the iframe know which plant's images to show by using the $_GET vars from the generated link. In this iframe, i needed to code a secure database connection defined by the $_GET elements. it counts the nuber of pictures, paginate them and everything. Thanks to myself !

Display image without showing its file path

Is there any way to show an image without its path. I mean not using HTML tag, I'd like to use PHP to show image. Because if I use HTML, someone can save or share that image.
Edit: I'm sorry about my question is not clear. I don't mean preventing saving image. I mean not showing the file path "/path/to/image.jpg" on URI or HTML. Because I don't want user copy and share the link which contains that image right on my website. The only way to share that image is to "Save Image As" and share it. Anyway thank you all.
This is my solution:
<?php
$image = 'new.png';
$content = file_get_contents($image);
header('Content-Type: image/jpeg');
echo $content; exit();
If the browser can view it, the user can save it. There's no way around that rule.
The only exception to this is if you recreate the image using 1x1 pixel divs of the colour of each pixel in the image, which is extremely heavy-handed and only usable in the slightest when the image is very small.
Even if you output the image with PHP, it will need to use HTML. There is no way to prevent a user from saving an image.
You could try using the image as a background-image with CSS, which will prevent non-advanced users from saving the image, but anyone who knows how to inspect the DOM or read CSS won't have any issue saving it.
Consider this - by the time a user sees the image on a page, their browser has already downloaded the file to the user's hard drive.
This is my solution:
<?php
$image = 'new.png';
$content = file_get_contents($image);
header('Content-Type: image/jpeg');
echo $content; exit();
You can give base64 of your image as src in <img> tag.
Example:
<img src="data:image/png;base64,--your 64--" alt="Red dot" />
As dtbarne explained any advanced user can get the image. However people do several things to prevent this form average users.
Disabling right click
Show in a popup with no tool bar
Set images with CSS to hide the path in as we use in <img src = "">
Load images using javascript
Generate dynamic images using PHP. It need check authentication and timestamp before generating the image.
There may be other ways too. Just for your consideration.
rendering anything in the page needs HTML in some way. this also means that it IS visible somewhere in the code - some directly visible, some require a debug tool to intercept.
you can make it impossible for people to steal the image in the following ways (some not ideal but does the job)
use flash/silverlight as a frame - though not ideal, it does help you prevent those who right-click and save. you can't view the flash source either.
use a background image - size a div enough to fit the image in it (since divs rely on explicit dimensions or children's dimensions to stretch it). the url is viewable on the CSS (unless it's dynamically placed)
use an image that has a "shield" - to do this, create a container div and place your image in it. in the same container, have a div that covers the image (absolute position, z-high z-index). this prevents the "right-click save" method. but the image path is in the source (unless it's dynamically placed as well)
you might think of canvas, but canvas is like a bitmap (therefore a picture still) so still a no-go from there.
all of which are not a fool-proof method. the only way you can avoid people from stealing owning images is to actually use a watermark. they may save but can't own it since it will have a watermark (like your name) across it.
If the client can see your image, users can save it anyway.

Add watermark to images

I've searched for ages for a solution, but I can't really find the solution to fit my needs.
So here's the story. Im creating a website and I really want to add watermarks to the downloaded images.
Yesterday I was browsing in a website called 9gag. If you haven't heard this website before, its a comic based website, and I found out that when you download an image, or access an image from anywhere else except their website, there's a 'watermark/banner' at the bottom of the image.
For example take this image:
link , notice no banner at the bottom of the image.
If you right-click, 'Copy image URL' , you get this link: image . See the banner now?
Im very confused on how they do it, and it would be great if we could use this on our websites.
Anyone with any ideas? Is it using any type of CGI?
P.S: I Wasn't sure what tags to add, So if anyone knows a better tag combination, please do edit it.
This effect is just a css trick. The image itself actually contains the watermark at the bottom, but the image tag is wrapped in a block that hides (overflow:hidden) the bottom 42 pixels of the image when it's being displayed in the page.
There are other things you can do that are more sophisticated (for instance, have the image served via a php script and comparing the http referer
header("content-type: image/jpeg");
if (!isset($_SERVER['HTTP_REFERER'])){die("alert('Restricted Access!');");};
$_u=parse_url($_SERVER['HTTP_REFERER']);
$_u=preg_replace("/(www.)/i","",strtolower($_u['host']));
$_i=$_SERVER['HTTP_HOST'];
$_i=preg_replace("/(www.)/i","",strtolower($_i));
if ($_u != $_i){
//handle this with gd or redirect
}
) but this will only work if someone tries to load the image from a different website or if they go to the image url... generally save-as will save the image from the browser's cache, so the css trick might be the best option you have (or a combination of these options). Fundamentally keep in mind that anything you show on the web can be captured (the code above isn't foolproof, and you can always prtsc).
GD library of php will help you doing that.
You'll need to create a new image using imagecreate function but adding some more "space" to the original size. Example: if I have an image of 200x200 (which you can retrieve using gd functions too) you'll need to create a 200x220px image using that function
Fill the new image with that gray color using imagefilledrectangle function
Copy the original image into the new one using imagecopy
Set the header's content type to image/type png gif etc..
Output to the image using imagepng or any other function that has the format you want.
I've had success with JQuery Watermark:
Jquery Watermark

How can I get Wordpress to ask for a custom image width on every image I upload?

I'm designing a blog for someone who wants to use a custom size for every single image.
The easiest way would be to just have a field on the image uploader next to where it asks 'medium, large' etc. saying "Width:_". Then the image will be scaled to be that width and embedded in the post at that size.
I can see there would be lots of ways to hack this in, or write a plug in to do it - but is there an easy way to do this, or an existing plug in?
Thanks!
Cole
If the user is logged in, writting a post/page,
once they click to upload a picture, if they are on the visual editor.
then just click on the image and select the "Edit Image" button that pops up,
the dialog window opens with 2 tabs at the top, click on "Advance settings" tab
and they can select the width & height from there?
The best solution I found to this was the plugin by Walter Vos, http://www.waltervos.com/wordpress-plugins/additional-image-sizes/ which allows you to specify new image sizes globally. It's well written and did just what we needed.

Image position and clipping

Does anybody know how to place an image in the webpage, but both position and clipping (maybe also resizing) are interactively done by user? I need it for my registration page, I've done some clipping and resizing from css and javascript, and it's not really solve the problem. If it's can be done by php, it will be perfect.
Here is a brief summary:
Let the user browse for and upload a
photo.
Validate the photo is of correct type
and dimensions using PHP's image
functions.
Show the user the photo in the
browser, along with a draggable DIV
that they can resize and move. This
is the cropping area.
When they click "Next", you transmit
the x,y,width,height of the DIV to
the server either by AJAX or simply
as hidden fields in a form.
Again, use the PHP image functions to
crop the image, and then resize it.
Save it to a permanent location.
Post a comment for further specific answers.
No matter what you're going to need to use either JavaScript or Flash to maintain intractability for a clientside resize of you image.
The following tutorial shows you how to use jQuery's simplified AJAX and PHP to upload an image to a temporary location, resize it, and save the resized copy where you desire.
Hope it helps!
http://www.webmotionuk.co.uk/jquery-image-upload-and-crop-for-php/
Try this class
http://www.verot.net/php_class_upload_samples.htm
All images that are being uploaded by user can be edited in anyway using php

Categories