I want to create a thumbnail from a bigger image. Therefore I used a script from a german tutorial found at http://www.php-resource.de/tutorials/tutorial,24,Thumbnails-mit-PHP-erzeugen,1.htm
The creation of a thumbnail from the hdd works nicely but i want to create a thumbnail from a image received by a http post request. ($inputImage = file_get_contents('php://input');)
Problem is that in the script the image is accessed from the local disk using the path.
eg. $size=getimagesize("PicPath/picName");
Can I access the image saved in the $inputImage variable?
Related
I hope you are all doing great. My question is
I am using cantaloupe image server which serves images according to user specify parameters in url using IIIF image API v2.0
Here is the url.
https://iiif.blavatnikarchive.org/iiif/2/baf__be12495f1d825e832cd7b66f0ee30c8adda804cd6c19e627537107b714b95356/full/!1000,1000/0/default.jpg (1000x1000 image)
https://iiif.blavatnikarchive.org/iiif/2/baf__be12495f1d825e832cd7b66f0ee30c8adda804cd6c19e627537107b714b95356/full/!512,512/0/default.jpg (512x512 image)
Image server takes time to process image for user defined dimensions and region extraction around 4sec. Therefore what i am doing is to pre generating some thumbnails using image server and storing them on amazon s3 so if user requests same thumbnail again and again I serve them pre generated thumbnail. Two benefits
1- Image server not computing it every time and load on server will be low.
2- Image serving through static thumb will be faster because it is pre generated.
Problem is now actually two servers are involved.
1- Image server for dynamic content creation. https://iiif.blavatnikarchive.org
2- Amazon s3 buckets for static thumbnails which were pre generated. assets.s3.amazonaws.com/image-name
I want to serve images using one url so end user don't redirect to different locations for same image with different sizes. So i decided to serve images using API
https://api.blavatnikarchive.org/baf__be12495f1d825e832cd7b66f0ee30c8adda804cd6c19e627537107b714b95356/full/!512,512/0/default.jpg (Apache using php)
In my api I know which request is for static thumbnail and i need to take it from s3 bucket and which one is for dynamic size and need to take it from image server. In API i need to get image using file_get_contents("url of image whether its amazon s3 url or image server url") so request downloads it first on my api server and then serve to client and client browser downloads it again which is time consuming and takes around 2s for one image which is not acceptable. Image serving time should be less than a sec. I am here to know is there a way to map my api url directly to image server and amazon server.
Like
If user type https://api.blavatnikarchive.org/baf__be12495f1d825e832cd7b66f0ee30c8adda804cd6c19e627537107b714b95356/full/!1000,1000/0/default.jpg
It should map to https://iiif.blavatnikarchive.org/iiif/2/baf__be12495f1d825e832cd7b66f0ee30c8adda804cd6c19e627537107b714b95356/full/!1000,1000/0/default.jpg (1000x1000 image)
Or specify
https://iiif.blavatnikarchive.org/iiif/2/baf__be12495f1d825e832cd7b66f0ee30c8adda804cd6c19e627537107b714b95356/full/!512,512/0/default.jpg (512x512 image)
Should map to directly static image thumb
https://baf-iiif-assets.s3.amazonaws.com/be12495f1d825e832cd7b66f0ee30c8adda804cd6c19e627537107b714b95356
or you can suggest me solution how i can gather things to one url? I want to keep user on my api url and dont want to use any redirection. How can i achieve this?
Many thanks.
Think stock images. You have a full-size original that can only be downloaded after purchase. You only want to have that image once on your server, at full-size. But you want to display that image in various places in smaller sizes (responsively reduced for mobile devices as well).
I've got various pieces of this puzzle, but have not been able to make them all work together:
With TimThumb or CImage I can resize the images server-side, and using jQuery I can dynamically change the image source based on the user's screen size.
With PHP and .htaccess I can place the image files outside of the webroot and route a spoof URL containing image name to the PHP file that will read the actual image and send a header with the image data. Fine.
But TimThumb and CImage work with the real image URLs and they test to make sure that the given URL is the actual file path of the image.
If I could send the actual image data to the image resizing script rather than the URL to the image, it should work out from there. Since the PHP script would be reading the image data, I could check to see that the user has been given the proper credentials before doing the read.
Are there any other solutions you can think of besides hacking TimThumb or CImage or writing my own custom image resizing script?
Thank you
The answer just came to me.
With .htaccess, route all images through the image processing script. On the first line of the image processing script I will include my own custom script. My custom script will check the GET parameters against the actual image to determine if the user has the credentials to be served the image being requested at the size it is being requested.
If so, let the image processing script continue, if not, exit out or change the GET parameters to that the image processing script serves a placeholder image.
VoilĂ !
I have script that create image gallery automatically from a folder. It also generates thumbnails if it doesn't exist. Everything works finely except a particular situation. thumbnail generation is invoked by user accessing the page (Psudo CRON).
I was trying to download a image to the folder of gallery in my server using wget (A big image) and at the same time some one accessed the web page and thumbnail was generated from the partial downloaded image, which created a partial thumbnail like below.
To fix this before creating thumbnail I started to check file last modification time and modification time after 600 micro second. if they are different I will skip the image thumbnail generation. This should work if the upload is not stuck anywhere and file is being constantly updated. But on other hand it will fail if the upload is not updating file in specified time interval
My code
//loop
$atime = filemtime($images_dir . $file);
usleep(600);
$btime = filemtime($images_dir . $file);
/* file uploading checking */
if ($atime != $btime) {
continue;
}
// code to generate the thumbnail
Is there any other way to solve this issue ?
Please note here user has direct access to folder and he can populate it any way using ftp/another script etc, that is uploading is not controlled by script.
Solution seems pretty simple to me. Don't put the images in your upload directory until the process of downloading the image is complete. You move them into the directory after they're on your filesystem.
Setting up a live image stream on a website, using images from a webcam. Trying to work out the implementation of it. The webcam takes a picture and requires a crop, resize and upload (not necessarily in that order), before it is displayed to the user, with a new image every minute. Currently I have a php script that does the cropping and resizing, while a webcam program automates the picture taking and uploading. However...
Uploading directly over the existing image causes an issue if the user reloads the page while the upload is taking place, resulting in a missing image.
Uploading with a different filename, then renaming it causes an issue if the user reloads the page during the renaming, resulting in a combination of both images.
Using a sequential filename system then gets tricky with the webpage requiring to know the new upcoming file every minute, along with a potential backlog of images.
Any suggestions are appreciated. Hopefully I'm missing something simple.
Thanks.
Just upload your image with different name, set the current image name somewhere, either in config file or MySQL, and after upload change it.
For now, i am able to download the image that i uploaded into my server. My upload is using php script to file open a image to store the .jpg file in the server. But i want to know how to retrieve the new image from my server to my android application. What i meant is every time the user upload the image, the image will replaced the old image file (using the same file name) in my server folder.
When i reload the image in my application, it still gives me the old image even though the image not longer exist. Later i found out that i need to go the url and refresh the image then the new image will be loaded in the android application. I want to know how can i refresh the url without using the browser to refresh the image every time the user upload new image. Thanks!
My question might not be clear/good but i really needed help and im new to android development
A pragmatic approach: When the user uploads a file, also make a txt/xml-file with the current date in it.
Make you Android application poll the txt/xml-file. Store the date in the txt/xml-file (in a database). When polling verify if the date in the file is newer then the one you stored. If it's newer, download your image.
After successfully replaced on server,you have to get url of new uploaded image as response & replace old url by new url.