I found a script - Upload and Crop image on this website http://onlinewebapplication.com/2011/08/image-upload-cropping-php-jquery.html Everything works fine, but I need to add my new name for new images...
When I upload an image -> before crop I can change file name, but it works only for big images, for thumb I don't have an idea because the variables are sent by AJAX.
My version works here - link
first input is for file path, second for new filename..
I need change name for big image and thumb, but it works only for big.
How send variable "image_name" to ajax_image.php ?
Anyone ? Please help me, I need this ..Thanks
You can change the name for the big image in this line:
$actual_image_name = time().substr($txt, 5).".".$ext;
and for the small image you can pass the name as parameter by changing this:
url:"ajax_image.php?t=ajax&img="+$("#image_name").val()+"&w="...etc
to this:
url:"ajax_image.php?sname=blabla&t=ajax&img="+$("#image_name").val()+"&w="...etc
also for the small image again change in ajax_image.php this:
$new_name = "small".$session_id.".jpg"; // Thumbnail image name
to this:
$new_name = "smallqa".$_GET['sname'].".jpg"; // Thumbnail image name
Related
I have absolute path of my uploaded image file and i want to get image file which i uploaded in my folder. So how can i get image file and how i can upload image.So i can perform image operation like watermark and rotate. So i have to get image file in code igniter.
i tried but it is not working
$upld_file = 'my absolute path';
$real_path = realpath($upld_file);
$img = base64_encode($real_path);
and i send $img parameter to upload image
I am getting "you did not select a file to upload"
C:\wamp64\www\codeigniter_project\assets/images/1551892667300.jpeg
This is my absolute path of my image
Thank You.
You don't need to get the absolute path of the image if you are storing the images inside a assets in the root of your project directory, You can access the image like this
echo base_url('assets/images/1551892667300.jpeg');
NOTE : you need to load the url helper first
You can try like this..
//define image path
$filename="C:/wamp64/www/codeigniter_project/assets/images/1551892667300.jpeg";
// Load the image
$source = imagecreatefromjpeg($filename);
// Rotate
$rotate = imagerotate($source, 90, 0);
//and save it on your server...
imagejpeg($rotate, "savedestinationpath.jpg");
That should be the file input name. eg: If your file browse input name is myFileInput then it should be $this->upload->do_upload('myFileInput')
Also make sure that you have set attribute enctype="multipart/form-data" for your form.
One nice example is here
I have a form in my Android app that send information to php server with an image pick button. I want to resize image before saving on server with php codes :
<?php
move_uploaded_file($_FILES['file']['tmp_name'],'uploads/'.$_FILES['file']
['name']);
$orgfile='uploads/'.$_FILES['file']['name'];
list($width,$height)=getimagesize($orgfile);
$newfile=imagecreatefromjpeg($orgfile);
$thumb='uploads/a/'.$_FILES['file']['name'];
$truecolor=imagecreatetruecolor(600,400);
imagecopyresampled($truecolor,$newfile,0,0,0,0,600,400,$width,$height);
imagejpeg($truecolor,$thumb,100);
unlink($orgfile);
?>
This code just resize jpeg images and another formats (png or gif and even jpg) saved a black image.
It is necessary to mention that name of image file changed to a random number like "32165465423" and I don't know the image format to use "imagecreatefrompng" or "imagecreatefromgif" in my php file.
I want a code like "imagecreatefromall" or another ...
Thanks guys(sorry for bad English)
You will have to detect the type of image, based on that you can run the function. See the one cool php library for reference
https://github.com/eventviva/php-image-resize/blob/master/lib/ImageResize.php#L77
I Have A Background Image Now I want PHP to Put Another Image On Top Of It (The Other Image Is Stored in A Variable)
Example variable $x
& My Background Image Is Also A Variable $back
Example ../img/back.jpg
Now i wish to Add The $x On The Left side of The Background
How May I Achieve this?
Like In This Pic There is The Green Part with a Shadow Image
How Can I replace that PART with another Picture using PHP?
(https://i.stack.imgur.com/IjK0o.jpg)
What i Have so Far
<?php
copy("https://graph.facebook.com/FACEBOOKID/picture?width=99&height=99", "picture.jpg");
$x = "picture.jpg";
copy("https://i.stack.imgur.com/IjK0o.jpg","bg.jpg");
$back = "bg.jpg";
?>
Combining images is part of image processing. You can use the gd library directly. However I recommend using an OO image processing library like intervention image, which is easier to write and understand.
// open the background image file
$img = Image::make('bg.jpg');
// Add the facebook image
$img->insert('picture.jpg');
// Save the image as a new file
$img->save('newpicture.jpg');
Read the documentation about the insert method to understand how to position the facebook image.
I'm trying to upload a photo using the following code. Suppose I'm uploading "abc.gif". It uploads in the proper directory as "abc.jpg". But my question is does the file type actually change?
$file_name = $_FILES['input_name']['name'];
$file_tmp =$_FILES['input_name']['tmp_name'];
move_uploaded_file($file_tmp, "abc.jpg");
This piece of code works perfectly while uploading.
But while making a resized copy of this abc.jpg using—
imagecreatefromjpg("abc.jpg") & imagejpeg()
—it shows a black screen.
When I move the file using the extension .jpg, does the file type actually change? Why does this problem occur?
Please verify the your imagecreatefromjpg("abc.jpg") & imagejpeg() function work correctly, you say file move successfully and display correctly so issue in the this image operation function which convert image into black image.
Thanks.
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' );