Jump to content

Masking the source of images?


virtuexru

Recommended Posts

is there a particular reason you cannot store these images locally ?

 

We have a data feed from another website that we pay for. Images are a part of this feed (they feed us their updates links into a MySQL database). I don't want people seeing where the images are being fed from though, that is the problem.

Link to comment
Share on other sites

Take the link from the feed, save the image locally.. then it appears as if it's from you.  ???

 

That's not the method I asked for, thanks though. Anyone else have any ideas? Maybe its possible not through PHP but through Javascript?

Link to comment
Share on other sites

Hi

 

Never tried it from a remote site, but read the image from the other location into php and then write out from php complete with headers.

 

header("Content-Type: image/gif");
readfile("http://www.domain2.com");

 

Might work (think it depends on a setting in the php ini file to allow remote reads like this, maybe allow_url_fopen ).

 

All the best

 

Keith

Link to comment
Share on other sites

If a server's going to remotely request it more than once, it might as well just save it.  You're wasting bandwidth otherwise.

 

I would agree that is best practice, and to cache it locally. But I presume he doesn't want a link to a real local copy either.

 

All the best

 

Keith

Link to comment
Share on other sites

If a server's going to remotely request it more than once, it might as well just save it.  You're wasting bandwidth otherwise.

 

I would agree that is best practice, and to cache it locally. But I presume he doesn't want a link to a real local copy either.

 

All the best

 

Keith

 

How would I go about saving a local copy automatically?

Link to comment
Share on other sites

Hi

 

Something like this (not tested as hacked from a script I have, so may be a typo or 2):-

 

$CacheFileName = '/SomeCacheLocation/SomeImage.jpg';
$RemoteFileAddress = 'http://www.remotesite.com/SomeImage.jpg';
$RemoteFileName = 'SomeImage.jpg';
if (file_exists( $CacheFileName ))
{
header('Content-Type: image/jpg');
readfile($CacheFileName );
} 
else 
{
$img = imagecreatefromstring(file_get_contents( $RemoteFileAddress ));
if ($img !== false) 
{
	$thumb = imagecreatetruecolor($width, $height);
	if ($thumb !== false) 
	{
		imagecopyresampled($thumb, $img, 0, 0, 0, 0, $width, $height);
		imagejpeg($thumb, $CacheFileName, 100);
		header("Content-disposition: attachment; filename=\"$RemoteFileName\"");
		header('Content-Type: image/jpg');
		readfile($CacheFileName );
		imagedestroy($img);
		imagedestroy($thumb);
	}
}
}

 

Basically, check if the image is cached. If so just output that. If not then create an image in memory from the remote location, create another local image and specify the width and height you want (so you can create a smaller / larger copy), copy the first image to the resized local copy, write it out as a jpeg, then put out the headers and do a readfile to read the cached image and output it.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.