imagemagick for thumbnail - php

I would like user to upload most of their photo albums online, would it feasible to create and save one in thumbnails folder and one in full size folder or generate thumbnails on the fly when the user access their album? It will be something like eBay does. Webspace is not a concern since I have an unlimited plan.

Store the thumbnails when they're uploaded, or better yet, create a thumbnail (and store it) when the image is first accessed.
Storing them means that the server won't have to do unnecessary processing on every page load.

Related

Uploading Image To Database & Storing Link or Storing Link To Offsite Image - Which is safer?

My sites profile system will have something like a Facebook profile, an image at the top and a profile image. My question is a simple one: Is it safer to upload the file directly to my server and store a link in the database or store a link to an offsite image in my database?
I think it depends on what you mean by 'safer'. If storage isn't an issue I'd upload to the server; your loading times will be faster and the image's existence will be guaranteed.

Webcam image stream for website implementation

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.

Keep track of user uploads within articles

just can't get my head around this.
I just finished my own WYSIWYG editor. It allows my users to upload images to embed in their article they are writing.
But how can i keep track of those user uploads ? I want them to be attached to the article, so that when i remove an article all images will also be removed. (keep my disk clean)
My first bet was to add an hidden input field to the article form for every uploaded image containing the image name, then on submit move all attached images from the tmp dir to the article image dir.
But this way a user can attach 100 times a picture to an article, remove them 99 times from the WYSIWYG editor and use only 1. Now i would have to save all the unused images. This seems like waste to me.
Any best practices on this ?
Don't worry about the edge case. Nobody is going to upload then deassociate 99 images.
You have to move the received files out of the tmp dir as soon as the (ajax?) upload sends them over. You cannot wait till the article submission, because the /tmp files would be gone by then.
Try to save your images with enumerated filenames like ArticleName.1.jpeg. And let your WYSIWIG editor inject uniqure placeholder tokens like {{img1}} on which you can see which images are factuall still in the article. (You can also try to deduce the file ids out from <img src="upl/articlename.1.jpeg"... since your WYSIWIG editor generates HTML.)
Anyway, on upload compare the list of enumerated {{img123}} tokens with the existing list of files.123.jpeg. Remove the unused.
Alternative: Do not remove unused images. Sell it as feature, since you now have more article history. And I guess the filesizes are negligible for most web sites.

TimThumb vs Saving Thumbnails

Just a quick question:
I'm working on revamping a script that serves vehicle inventory to users.
The site receives thousands of hits per month with many pageviews per visitor.
My question is this:
I am going to have 7 images for each vehicle in the new system.
1 Main Product Photo
6 Interior Extra Photos
The 6 extras will be viewed as a thumbnail, with the ability to load the full image in a lightbox.
Now, to the question:
Should I use TimThumb (or similar) to resize the images to Thumbs on the fly, OR should I create a thumb directory and save a thumbnail for each image as it is added to the server?
I use TimThumb for the main image, and it works quite well, but I'm debating which is easier on the server for the other 6 images.
Thanks!
it might not differ while the load is low, but rebuilding thumbs on request is quite resuorce consuming. if server load matters, you should save thumbnails.
there are two ways to do this:
- generate all thumbs on image upload
- generate thumbs on first request and save them
The easiest on the server is to use javascript on the client side. Its a little slower loading for the user if there are a lot of images being served but if there are less than 10 it should be okay. Look into using jQuery and CJ Object Scaler http://plugins.jquery.com/project/cj_object_scaler

Storing pictures per user on website (php)

Users of the website need to able to store images in their "area" , should I store these in the database directly or create a directory for each user.
Or should I just have a single directory for all images and in the database store a list of images that each user owns?
I'm looking for the most effecient way, which I think is a folder for each user?
If you have many pictures per user like avatar and gallery of photo created by the user then use separate folders named with the user id or a hash of the user id.
If you only store avatars have one big folder where the name of the image is the user id or hash of the user id.
It depends on how many pictures there are.
If there is only one picture per user, then perhaps all in the same directory.
However if you have albums and such, there can be millions of photos with all the users photos in the same folder. This would be very slow to search in. Then I'd go with one folder per user.
Also, never give direct access to the folders. Use your database to link to the files.
Better use folder or a cache folder. You can also use resizing functions for the image, so if user upload a large scale picture. Your script will manage to create different sizes, like avatar pics. And cache those images. So thumbnail or avatar viewers only viewing the cache image of the original image. And the large image is usable for future work, like a bigger preview of the avatar.

Categories