PHP - Imagemagick Help
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 Similar TutorialsI 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 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 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 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 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. 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. (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. hello dear php-experts and freaks how to view photos and to rapidly change the major categories i have several hundred images (photographs) taht i want to view on opensuse linux version 13.1 i want to view the images - and of while doing so i want to turn the colored images into b/w Question; which is the best - ie. the quickest way to do so. note; i have installed the following thigns on my opensuse 13.1: - gimp the great grahical tool - digicam - the great tool to view images and pictures - Gwenview Version 4.11.4 on KDE 4.11.5 so again here the question: which tool allowes to view the color(ed) image and to turn it - on the fly - in to black and white? BTW: can i tell linux to swith the colors - in general - to black and white? is this doable... looks like we could write a small shell script, utilizing imagemagick. maybe like this: Code: for i in *jpg ; do mogrify -colorspace Gray "$i" ; done this is just a quick hack. i have tried. See more bleow: Also, it's not interactive and simply changes all jpg's to grayscale, even if they already are grayscale. please note that we need to have some more things about imagemagick. well see the results: martin@linux-70ce:~/Bilder> martin@linux-70ce:~/Bilder> for i in *jpg ; do mogrify -colorspace Gray "$i" ; done mogrify: unable to open image `*jpg': Datei oder Verzeichnis nicht gefunden @ error/blob.c/OpenBlob/2643. mogrify: no decode delegate for this image format `*jpg' @ error/constitute.c/ReadImage/552. martin@linux-70ce:~/Bilder> |