I'm currently allowing users to upload an img and then I save the image as folows:
$tmp = imagecreatetruecolor($configWidth, $configHeight);
imagecopyresampled($tmp, $src, 0,0,0,0,$configWidth,$configHeight,$origWidth,$origHeight);
imagejpeg($tmp, $_SERVER['DOCUMENT_ROOT'].$folder.$newFileName,90);
I then show the image to the user so they can crop the image.
I wanted to ask if I could display the image for cropping without saving it - eg: could I show the image to the user for cropping from the tmp_name - the tmp php image?
I'm not sure if this is possible but it would avoid having to save an image that is then later deleted post cropping...
thx
could I show the image to the user for cropping from the tmp_name - the tmp php image?
No the image is outside the webroot also the image will be deleted when the upload script finishes execution.
With some html5 methods you can show an image on a page without uploading it. see https://developer.mozilla.org/en-US/docs/DOM/FileReader#Example
Related
I have 2 different scripts for handling images:
The first one is a watermark script for watermarking images on the fly:
$imgpath=$_REQUEST['filename'];
header('content-type: image/jpeg');
$watermarkfile="assets/img/logo_variations/logo_watermark_75.png";
$watermark = imagecreatefrompng($watermarkfile);
list($watermark_width,$watermark_height) = getimagesize($watermarkfile);
$image = imagecreatefromjpeg($imgpath);
$size = getimagesize($imgpath);
$dest_x = ($size[0] - $watermark_width)/2;
$dest_y = ($size[1] - $watermark_height)/2;
imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
So the image URL for a watermarked image is: http://example.com/watermark.php?filename=assets/img/temp/temp_share.jpg or since I'm using mod_rewrite to "pretty up" my URL: http://example.com/watermark/assets/img/temp/temp_share.jpg.
Works like a charm and my reason for doing so like this is because this is on a modeling website where I want to display the images without watermarks but I use a jquery script to change the image source of the image gets right clicked(assuming a user is trying to save the image).
The script only changes the source of any image with a class of img-protected.
I've written it to ignore any image with watermark in the URL so that it doesn't try to change the already watermarked image which would result in a url like: http://example.com/watermark/watermark/img.jpg which would result in a broken image. The other part is written to remove http://example.com from the original source so I don't end up with http://example.com/watermark/http://example.com/img.jpg.
$('.img-protected').on('mousedown', function (event) {
if (event.which == 3) {
if(this.src.indexOf("watermark") > -1) {
return false;
}
else {
src = this.src.replace('http://example.com/','');
this.src = 'http://example.com/watermark/' + src;
}
}
});
All of this works exceptionally well until I added another image handling script:
I'm using TimThumb.php which is an on the fly image resize script I use for creating gallery icons instead of uploading an icon and a full size image(this is how I wish to keep doing so as well).
The problem I am facing is this:
If I have an image that is being turned into a thumbnail using TimThumb.php which I renamed to thumb.php on my server the URL is http://example.com/thumb.php?src=gallery/goth/industrial_brick/5361ae7de9404.jpg&w=350&h=500a=c&s=1&f=11 which gives me an icon for 5361ae7de9404.jpg.
All of my icons have a class of img-protected which means on right click the above URL is going to be changed to the watermarked one.
This is where it fails.
The outputed URL when right clicked is http://example.com/watermark/http://www.example.com/thumb.php?src=gallery/goth/industrial_brick/5361ae7de9404.jpg&w=350&h=500a=c&s=1&f=11 which results in a broken image.
I manually tried making the URL into http://example.com/watermark/thumb.php?src=gallery/goth/industrial_brick/5361ae7de9404.jpg&w=350&h=500a=c&s=1&f=11 to see if that would change anything but it still results in a broken image.
What I need is to be able to also watermark the generated icons from thumb.php using watermark.php.
Is there a way to combine these two scripts or a workaround to make this work?
I'm at a complete loss here.
EDIT: I am fully aware that advanced users can still acquire the non watermarked image since it's already been downloaded to there device, but I don't expect a high volume of users to visit this particular website as this is simply a local models portfolio.
I want to know that how can I overwrite images when they uploaded to server in php. For example I uploaded a photo to a folder as soon as I upload another image it will take place of previous image. Image name is not same it may differ. Thanks
Delete the previous image before uploading the new one using:
$path = $_SERVER['DOCUMENT_ROOT'].'img/img.jpg';
unlink($path);
This code basically assigns the path of the image to $path and deletes the image using unlink($path);
This code will upload the image to the server ,then user can crop the images.
http://www.webmotionuk.co.uk/php-jquery-image-upload-and-crop/
In the code,maximum file size that you can upload is defined as 3 MB.When you upload a file which is more that 3 MB,it has to show this error to user "Images must be under ".$max_file."MB in size" But this code always shows Error!
Select an image for upload"
Is there any better plug in than this ?
Thanks in advance!
this is the latest link for uploading image not only for jpeg as your link is only for the jpg image. Check this link -- http://www.webmotionuk.co.uk/php-jquery-image-upload-and-crop-v11/
Scroll down and grab this bundle as shown --
PS--
Check your image upload settings as well in php.ini
I am working on an upload script that also resizes/rescales an image.
Currently it is working by uploading the image, moving to the upload dir (site.com/upload) and then resizing, and afterwards deleting the original again...
Now my question is:
Can I do this without moving the original to the upload dir and even better, also keeping the new file in tmp so I the user can afterwards confirm the image (so If they don't want it and just hit the 'back' button it won't stay in the upload dir.)
Current code:
move_uploaded_file($_FILES['file']['tmp_name'], 'resize-upload/'.$_FILES['file']['name']);
$filename=$_FILES['file']['name'];
$Imagick=new Imagick();
$Imagick-> readImage('resize-upload/'.$filename);
$Imagick-> scaleImage(200,200,auto);
$Imagick-> writeImage('resize-upload/resized-'.$filename);
unlink('resize-upload/'.$filename);
You can't. You don't have the access to the image if you haven't moved it yet. But you can generate more than one thumbnail at a time from same image/object and if you are storing/keeping the original also then you don't need to unlink it either.
Another way would be to use flash and resize the image on the client side and then only save the resized image.
I am working on building gallery where the user uploads all the images. I had tried to use GD originally but found that it used way too much memory when dealing with images from a digital camera. So I have been looking into ImageMagick and ran into this problem.
My end goal is to resize the image and then upload it. I am not sure if this is possible with ImageMagick or not. I have gotten it to resize the image after upload but it doesn't save the resized image, just the original size.
This is the code I am currently using: ($image is the path to the file on my server)
$resource = NewMagickWand();
MagickReadImage($resource,$image);
MagickSetImageCompressionQuality( $resource, 100);
$resource = MagickTransformImage($resource,'0x0','660x500');
Any input would be appreciated,
Levi
Your code will send the modified image to the client (the web browser), but it will not save it to the server (replacing the original image, for example)
To save the image, use:
MagickWriteImage( $resource, 'new_image.jpg' );