This may be hard to describe...but...
I created some simple PHP forums and I have the ability for users to post image links and I want the image to appear on the page. BUT...my forum posts are inside an iframe and if the width of the post is too wide it would cut off the side so I want images to only be so wide. Any concepts for getting the image to fit? I wonder if there's some auto resizing option in HTML or a way for PHP to get the file width/height remotely and generate the HTML for it?
you can use the max-width attribute in css eg:
iframe img{max-width: 500px;}/*or whatever your max wants to be*/
and in php you can use
<?php
list($width, $height) = getimagesize($yourfilename);
you might need to wrap getimagesize in a if because it will cause it to return false on failure
Related
I have an iframe that shows a picture generated by a software on the server. The image size is sent in pixels to the software by a parameter in the command line.
The iframe size is set relatively, using <iframe width="100%" >, no problem with that. But in small screens, if the iframe gets smaller than the picture it causes a bad effect, with undesired scroll bars to show the hidden parts of the image.
Is there a way to know the size of the iframe in the browser, or the screen itself, so I can send the correct size to generate a picture that will fill properly in the iframe?
(I guess this is used by responsive themes)
EDITION: I'm reasking this in another way here How to make it sure that an iframe content fits it?
The best approach would depend on the method in which the image is loaded into the iframe. The size of the iframe would have to be determined on the client end, so it would be out of reach for PHP.
I'd personally load the image with PHP on the server end and avoid iframes. If you are loading the image after the page is loaded, you might want to reset the iframe's size using javascript(or jQuery).
If you could provide more detail about how the image is loaded into the iframe, it would help figure out what exactly you're looking for.
I have an online portfolio I am working on, I am fairly new at both JQuery and PHP, but am working my way through all the issues, however this one has me stumped.
So, I have a seamless iframe for loading my images from the navigation, I am trying to build it so that the images all line up horizontally, normally I would load everything and dynamically change the wrapper for the browsers viewport, however since the images are coming server side form a PHP script / mySQL database, I am unsure of how to alter any of the image or div contents.
Everything is a loaded in a While loop after a user selects which portfolio to view.
Here is a link: http://tbremer.com
Any help would be greatly appreciated!
Let me know what other information is needed!
It is possible to get the width and height of an image from the server.
Ex:
$image_data = getimagesize(PATH_TO_IMAGE);
var_dump($image_data);
Better yet, you could use "list" to retrieve the width and height:
list($width,$height) = getimagesize(PATH_TO_IMAGE);
Whereas, the first two returns from the array are width then height, they are then set the the variables, oddly enough $width and $height, and you can use those to re-size your iframes.
Is it possible to display some php content within an HTML image (say display on the screen of an iPhone where iPhone being an image)
Well, if you just want to overlay text on an image, why create an image at all.
you can use css background image(iphone in this case) for a div and the insert your phpp content as a child of that div. Using proper css styling and positioning, you will get your desired look. Its simple and less server consuming than going the image creation way.
You could generate your own image on the server using the GD library to overlay your content onto the image and then send that to the client.
You can use CSS to achieve the same effect, without requiring any server processing; however, it must be an image, you might want to check out the image processing library that allows you to manipulate images using PHP http://php.net/manual/en/book.image.php.
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.
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