On my site I have given an option to user to choose thier profile image
Type link of an image
Image is a url link, and first I want it to resize to 400x300 (image's original size doesn't matter), and then display it on my web page.
Something like below:
<img src="http://mywebsite.com/resize.php?image=http://someotherurl.com/upload/image2.jpg&width=400&height=300" />
anyone knows this kind of script, please tell me how to solve this issue.
Thanks
A recent post:
https://stackoverflow.com/questions/1302464/php-image-resize-my-upload-script
has some code and comments that may give you some pointers. Otherwise may I suggest
http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php.
Good luck!
If you have the GD extenstion, you can use imagecopyresampled (the documentation also features some examples). However, if the image to be resized is large and there is a low memory limit on your server, you may run out of memory.
I don't have ready to use source code, but it should look like:
Load image pointed by image parameter into object of ImageMagick (or other graphics library).
Resize it.
Send content to output stream.
Optionally you could:
Check if loaded file is image (plus other validation checks).
Save resized image on disk and serve it from disk next time (if you do it often).
Check docs of you favorite graphics library used in PHP for details.
Good luck!
Use the Class called - class.upload.php.
Find it at: PHP Classes
We use it at all times in many of our work.
The name is deceptive but actually it is an uploader as well as image processor. It has a very big list of functionality for resizing images, adding text to images, converting formats, etc. etc.
There is sample code which shows how to read an Image from server, modify it and finally send it directly to browser without having to create a temp file on server.
HTH
Related
I had created one wordpress site. I want to make all post downloadable by converting it to image.
I tried using canvas but didn't succeed.
Can any one suggest me better working way on wordpress which lets me convert my post to image and make it downloadable?
I want to make post covered with specific div so that i can define size of content to be downloaded.
Like this HTML2CANVAS but I am unable to do.
PS-I have very small size of content in every post
I think your options are
Use some third-party service, such as http://web-capture.net/ or https://www.url2png.com . Most of them, especially the ones with API that you can call on-demand, will cost you, but there are free alternatives.
If you have access to linux console and some basic knowledge about it, the best approach is to run a real browser (if you're using a headless server, use Xvfb) with your post URL and make a screenshot with ImageMagick. You can crop the image to remove browser header etc. A working-grade explanation here http://www.leonardteo.com/2011/07/taking-server-side-screenshots-of-websites/ .
In both cases PHP will be just the trigger, whether it will call third-party API or your local shell script.
I'd also suggest to avoid JPEG format as it doesn't really play well with text. Use PNG instead.
You may try rendering the text with imagettftext() as #Progrock suggested, but this will be a huge pain, because you obviously have text with more than one line. First you need to determine the width of your image, then use imagettfbbox() to roughly estimate how many characters you can fit into one line, split your text into chunks of that size and write then one by one, adding the Y coordinate. Bonus points if you need paragraphs here... Make sure you're using monotype font, because it won't ever work properly with variable-width letters. look through comments here http://php.net/manual/en/function.imagettftext.php.
My advice - stick with the browser :) You can resize the browser window and crop the extra part.
I've made some research and couldn't find the answer. Is it possible to detect an image resolution using an upload file field?
Right now, I can detect the size of an image in pixels...But I would need it to find the "inches" size.
And I also need to find out the resolution of the image.
Using Javascript would be the best...if possible, if not...PHP maybe?
Thanks!
You'll have to do this once it has been submitted. Check out the getimagesize function in PHP - http://php.net/manual/en/function.getimagesize.php
You will need a browser that supports the FileReader interface - read more at Is it possible to get info from a file on the client side without uploading the file?.
There are some javascript libraries reading such information like EXIF from the file:
JsJpegMeta
ImageInfo - although I'm not sure whether it gets its binary data by ajax from already uploaded files.
If you want to offer this functionality to user with browsers not supporting this, you will need to upload the file and do it serverside (with PHP).
I've recently started trying to increase my sites performance. One of the biggest obstacles I have are the number of thumbnails being displayed.
I currently use the full size image and scale it down by defining a height/width value in the img tag. This doesn't seem very efficient so my question is whats the recommended way to display thumbnails? Should I maintain a second table in the DB for thumbnails or is there a better solution?
Processing images takes its (cpu) toll, you should better avoid it where possible.
My advice:
Create the thumbnails while uploading the images into separate image files, this way you can determine when to create/resize them - and not during runtime.
If you want the links to the thumbnails in a separate database field or derive it from the original name, is entirely up to you - both ways work.
This makes additional performance boosters easier to implement too (p.e. caching).
I've implemented a similar process in a php based project, its a good way to scale out. In my case, I am creating the thumbnails nightly via cron, because system load is very low in that time.
If using an uploader to get the images on your website, have PHP resize the original image and upload both the original and a smaller thumb with some kind of prefix in the name.
This way you can easily get the images from your database and just use "filename.jpg" for your normal images and "thumb_filename.jpg" for your thumb.
Same can be done without an uploader of course but you'd have to manually create/upload the thumbnails.
For example create seperate folder in images call it thumnails (images/thumbnails) add there put files prefixed with file size for ex: "original_file_name_200X200.jpg", store on database "original_file_name" and extension "jpg" to seperate fields (name, ext) then when you need to display it select name add size prefix and add extension you get /images/thumbnails/file_200X200.jpg this way you can add later more sizes leaving original untouched.
You are looking for something like what can be found here: http://dtbaker.com.au/random-bits/php-simple-image-resize-thumbnail-generator.html (this turns all images into jpegs)
Like #martincarlin87 stated - Just need to add a check to see if it exists in the thumbnail directory and either send the information or create and send it through. This can be turned into a function as well.
I use phpTumb to create thumbnails on the fly.
You could also use it while uploading a picture to change its dimesions.
It has many other features. Check it out.
you could use a program like imagemagick to make proper thumbnails.
If its your personal site you could batch resize (theres a powertool for xp that does this) and then upload to a 200 directory and change your code. Obviously this relies on you uploading the images.
imagemagick will need to be installed on the server but will resize and allow you to play with the size of the images
I am working on a site at the moment, that requires the admins of the site to be able to upload pretty much any size of image, I then need to find a way to get the image down to the size required for the front end of the end the site, all this needs to be done without know what size of image the user is uploading, but the image always needs to scale to 209x293 without looking awful.
Is this even possible?
You should argue with your client, to forget that rule(accept ANY image), and accept rather, only images in that proportion, or better, you can use a tool to crop the image, forcing the user to crop an image in your needed resolution.
Jcrop is a library in Jquery which can help you a lot if you want to create that cropping feature.
Don't know your precise requirements, but since you tagged it with CodeIgniter, you can check out the Image Manipulation Class which has everything you need to do the job.
Not knowing the size of images before uploading is, you know, quite a common problem...Just be careful of the MAX SIZE, which is set in your php.ini.
You might find useful also the page on file uploading right in php's manual.
I'm creating a web app that allows users to specify an image url to display an image along with their submission.
To avoid some potentially large images and odd sizes, i'd like to use PHP to limit/resize the image before it gets output to the browser (I know i could use max-width in CSS but this is unnecessary downloading)
Is this possible?
PHP has a library named GD. It's fairly easy to check the size of an image with the getimagesize() function.
You can find the complete code for it with 2 module/extensions: http://www.fliquidstudios.com/2009/05/07/resizing-images-in-php-with-gd-and-imagick/
a comparison of them can be found here: http://dreamfall.blogspot.com/2008/02/php-benchmarks-gd-vs-imagemagick.html which may be of use if you want optimize features.