PHP - Using The Exec() Function To Contain An Imagemagick Command
Hi I'm trying to resize pictures for thumbnails I can do this correctly at linux command line with the following command convert ideologies.jpeg -resize 300x200 ./Thumbnails/testphp.jpg However trying to wrap this in PHP doesn't seem to work // Upload file to server if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){ // Insert image file name into database $insert = $conn->query("INSERT into Threads (Title, ThreadBody, filename) VALUES ('$Title', '$BodyText', '$fileName')"); if($insert){ $statusMsg = "The file ".$fileName. " has been uploaded successfully."; exec("convert {['fileName']} -resize 300x200 wankertestphp.jpg"); } If you look above I do successfully hit the "The File has been uploaded successfully" line so it is entering that If statement. I've also checked the Threads table with a Select * from Threads and I can see the $fileName variable is entering there. I've tried numerous different ways around the $fileName variable (removing the brackets...removing the brackets and the apostrophes")
Any help is appreciated. Similar Tutorialsis there a way to excute the system() command here but not wait for it and just let it go in the background? And something that wont boggle down the system too much? Thanks! Code: [Select] $this->db->insert('jukebox', $data); echo '1'; system('ffmpeg -i ' . $id . '.mp3 -acodec libvorbis -aq 60 ' . $id . '.ogg'); I want to do something like the following: exec('open /Applications/Safari.app'); I can run exec on other commands like: $output = exec('ls -ll); echo $output; And I can run the open command via Terminal, but I can't seem to run the open command via a PHP page using exec(). I've tried the permissions of the .app file at 777 and the open binary at 777. Any suggestions? Hmm, hello everyone, i'm running my php in an ubuntu server and I'm trying to run a command using exec (i.e. 'echo 1 > /var/www/test.txt') but I always get a permission denied issue, although i've already changed the permissions to 777 (read-write-execute) Any solution? hi guys. i'm new to php and Apache and i have a problem. i'm trying to execute an exe file that i have in my folder, and the code i use is Code: [Select] echo exec('test.exe');i have tried using this with and without the ".exe." and still no luck. i have also tried using a different path Code: [Select] echo exec('C:\Windows\System32\mspaint');now these codes work when i run them from my php editor(PhpED), bun when i try running it on Apache it gets stuck. (just shows the web page as loading with no end. please help me out. i'm guessing it something with security. also if there is any other code i can use please let me know (i have also tried using system) I have a username alam for the server I have sudo access to execute linux commands. I could configure almost all files the root can do. I wrote this script on the server for test as I need to provide the server some functionality ----------------- Code: [Select] <?php $cmd="ls -l"; echo exec($cmd,$ret_value) . "<br />DONE"; echo "<pre>".shell_exec($cmd)."</pre>DONE"; ?> ------------------ I get the OUTPUT as follows - ------------------ DONE DONE -------------------- I am novice user of Linux however any kind of help will be appreciated .......... how do i enable exec() in php.ini? where is php.ini? cant find it in the directories in my site. Hi, I'm trying to build a 'simple' page to improve a process where I work.
I'm wanting to do this.
Read either the last line, the last 10 lines, or something I decide on from a log and display the output in table rows and columns.
I've done this before with loops and db query's, but don't know how to approach it using php only as this is the first time I'm using it.
So right now I have this in a table but it will only display one row.
<tr><td colspan="5"> I have a PHP script containing the function exec which works fine in PHP 4 in IIS 7 on Windows 7. However this function does not work in PHP 4 in IIS 5 on windows server 2003. But I have to make it work there because that is what we have on our web server. Can someone provide a solution? Hey guys I usually code in C and I started looking into PHP which I think is pretty good. I'm wondering if there's a function that can be used to execute a command from a remote server on my local machine??? As example if I'd like to have a PHP page/script running on my server which when logged onto would display me a page with buttons like "PING, NETSTAT, IPCONFIG, TRACERT" and when clicked on it would exec those commands but not on the server but from my machine??? So that I would get the PING from my local machine to google.com instead of from the server to google.com ??? making any sense ??? thanks Hello all
I'm new to this forum. I've been struggling on this problem for a few days now.
I’m writing a script to automatically push code to a git server. exec(‘git config user.name "’ . $userName . ‘"’); exec(‘git config user.email "’ . $userEmail . ‘"’); exec('git checkout -b ’ . $branch); exec(‘git add --all’); exec(‘git commit -m "’ . $message . ‘"’); exec('git push origin ’ . $branch);
When running the last command, the script stops and asks for a user name, then a password. I tried other forums, searching the net. I'm frustrated...
Thanks in advance. I have a line of code that has been working for over a year, then two days ago it failed in a few areas on my site and I hadnt made any changes. I contacted the host and there was no server updates etc. Its a php/imagemagick issue, basically the "widthxheight^ - Minimum values of width and height given, aspect ratio preserved" command does not work and fails to import the image at all when I add ^ to my code. I need it though and im getting fustrated, for now ive changed my code to: exec("convert $path1 -thumbnail 200x180 -colorspace rgb -gravity center -extent 170x150 $path2"); which works ok but is not spot on like it was before, what I really want is exec("convert $path1 -thumbnail 170x150^ -colorspace rgb -gravity center -extent 170x150 $path2"); What ever I do I cant get ^ to work anymore but oddly all other imagemagick commands are fine. Hi all I am trying to resize an image using imagemagick but it won't let me use the below code as it shows a security error 'exec() has been disabled for security reasons': Code: [Select] $scale = '158x158'; $go = WEB_UPLOAD.'/test/images/'.$image; $stop = WEB_UPLOAD.'/test/images/'.$image_medium; exec("/usr/bin/convert $go -resize $scale\> -quality 100 $stop") or die("Error creating 158 x 158 image."); unset($scale, $go, $stop); How do I write the code that resizes the image without using the exec function? Many thanks for you help! Pete Hi all I need to re-write the below code so that it doesn't use the exec function: Code: [Select] $scale = '74x74'; $go = WEB_UPLOAD.'/test/images/'.$image; $stop = WEB_UPLOAD.'/test/images/'.$image_small; exec ("/usr/bin/convert $go -resize $scale\> -quality 100 $stop") or die("Error creating 74 x 74 image."); Many thanks for your help. Pete Hi all I'm using MAMP and trying to install ImageMagick. Is there a way to test if it is correctly installed when using MAMP? ttmt Hi all I have created the below script to resize my images and it works fine for landscape images but if you select a portrait image it saves it as a landscape image. How do I modify the script so it keeps the same aspect ratio? Code: [Select] copy($_FILES['image1']['tmp_name'], WEB_UPLOAD."images/adverts/test/".$_FILES['image1']['name']) or die("Error uploading image."); $ext = strtolower(substr($_FILES['image1']['name'], strrpos($_FILES['image1']['name'], "."))); $rand = rand(1, 100000000000000); $name = $rand . $ext; $image_small = $rand . $ext; rename(WEB_UPLOAD."images/adverts/test/".$_FILES['image1']['name'], WEB_UPLOAD."images/adverts/test/".$name) or die("Error renaming image.");; $go = WEB_UPLOAD.'images/adverts/test/'.$name; $stop = WEB_UPLOAD.'images/adverts/test/'.$image_small; exec ("/usr/bin/convert $go -resize 10%\> -quality 100 $stop"); unset($scale, $go, $stop); Many thanks for your help. Pete Here is the code I have right now:
<?php header('Content-type: image/png'); $grey = new ImagickPixel('#ebebeb'); $orange = new ImagickPixel('#0f92d6'); $image = new Imagick('assets/lop.png'); $layer = new Imagick('assets/lop-base.png'); $layer->thumbnailImage(200, 0); $image->thumbnailImage(200, 0); $layer->paintOpaqueImage($grey, $orange, 100); // Place layer on image $image->compositeImage($layer, Imagick::COMPOSITE_SOFTLIGHT, 0, 0); // Let's merge all layers (it is not mandatory). $image->flattenImages(); echo $image; ?>It's putting the layers on top of eachother very nice. The thing is is that this involves some heavy shading at times depending on the bunny breeds. Here is what the base image ($image) looks like: And here is what the overlay ($layer) looks like: This is what the outcome looks like versus the intended result: I've tried almost all of their composite constants.. I can't figure out how to do this or the best way of going about it. Because the colors are going to be dynamic throughout the site so I can't just save a .png of every color combination.. and there will be more colors layered on top of eachother like markings/patterns/etc. Thanks for any help! This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=346533.0 Need to change the letter spacing.. help? $tag = 'www.xxxxxx.com'; $text_draw->setFontSize(8); $text_draw->setFillColor("black"); $output_image->annotateImage($text_draw, 123, 34, 0, $tag); $text_draw->setFillColor("white"); $output_image->annotateImage($text_draw, 122, 33, 0, $tag); Hi, Very new to PHP and am enjoying learning the ins and outs etc, but while creating my mam a website, ive ran into a problem while uploading, resizing and saving the file to my web host. Initially i used imagecreatefromjpeg, but this was taking too much memory up, so opted to use imagemagick. All of the features work apart from the file getting saved to the uploads directory on my web space. They always get saved to the root. If someone could help i would be very grateful. The code ive got currently is: <?php // If the form has been submitted do this if(isset($_POST['submit'])) { // Temporary upload image name $original_image = $_FILES['photo']['tmp_name']; // Get the image dimensions $size=GetImageSize( $original_image ); // Name to save the image as - in this case the same as the original $new_image = $_FILES['photo']['name']; // Maximum image width $max_width = "600"; // Maximum image height $max_height = "300"; // Resize the image and save exec("convert -size {$size[0]}x{$size[1]} $original_image -thumbnail $max_widthx$max_height $new_image"); echo "File uploaded<br>"; echo "<img src=\"".$new_image."\">"; } ?> Hopefully someone could help Many thanks, Matk. (1) What does this actually do? (compress it?) $image = imagecreatefromjpeg("image.jpg"); header('Content-Type: image/jpeg'); imagejpeg($image); By using this rather than displaying by using www.site.com/image.jpg it reduces file size of an image from 2.5mb to 0.5mb !! (2) ImageMagick can't get these results. Am I doing something wrong? If I change the pixel size of an image in ImageMagick then I can reduce its file size, but (1) above reduces file size regardless of changing pixel size. |