SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Thumbnails in Imagick with PHP

    I downloaded Imagick and made sure it was installed PHP's ext folder. I uncommented the extensions line in the php.ini file to activate it. I restarted the server.

    I went to a site and copied the following text to test out the thumbnail script. I saved the file as thumbnail.php and put it with my other working php scripts. I put tc5.jpg in the same folder as this php file:

    PHP Code:
    <?php

    header
    ('Content-type: image/jpeg');

    $image = new Imagick('tc5.jpg');

    // If 0 is provided as a width or height parameter,
    // aspect ratio is maintained
    $image->thumbnailImage(1000);

    echo 
    $image;

    ?>
    (This is the full contents of the php file.) This is my first Imagick script and it does not display the tc5.jpg image. The screen displays: http://localhost/thumbnail.php

    Testing other php pages in the same folder shows they work fine. Am I supposed to add something before or after the php tags to make the above script work? Is there an extra step or two I'm missing to make Imagick work?

    I've been to several sites for Imagick and they are not very newbie-friendly (basics are not fully spelled out for rank newbies like Sitepoint books are), so I came here.

    Thanks for any help!
    Steve

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Have a browse through rubble's imagemagick scripts and examples. They are easy to follow and give you some code to get your teeth into

    specifically look at:
    http://rubblewebs.com/imagemagick/
    http://rubblewebs.com/imagemagick/codes/codes.php
    http://rubblewebs.com/imagemagick/compair.php
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you. I had already gone there. I need instructions even more basic. See my notes below, based on his own page of instructions:

    Windows:

    1. Download and run the latest binary release for windows from here. ***Okay, I can do that.***
    2. Prove image magick is running by opening the command prompt and type: convert -version ***Does this mean going to Windows > Start > Run? If so, it doesn't work.***
    This should display the version of ImageMagick installed.***What do I do with that version information?***
    3. To use:
    1. Open Command prompt.***Does this mean going to Windows > Start > Run? If not, where is the Command prompt?***
    2. Using cd directory name get to the directory with the original image in - in my case I went
    cd \ to take me back to the root
    Then after the c:\ prompt
    cd Documents and Settings\Barney\My Documents
    ( You can look at image properties to find the path you need. ) ***How do I "look at image properties"? Is this the same as going through My Computer and looking in the My Documents folder?
    3. I then ran convert test.jpg -resize 50x50 output.gif***This instruction assumes I already know something else. What those details are I don't know.***
    I now have an image called output.gif in the My Documents folder.***Good for you, sir! How do I duplicate that in PHP so it makes thumbnails on my web images?***

    It is vague instructions like the above that help me appreciate the Sitepoint books even more! The above was not written for someone like me just starting out. Can you fill in the blanks for me, based on my questions above?

    Thanks,
    Steve

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Steve
    1/ ok you've done that!
    2/ Windows > Start > Run and then type cmd
    this should open up the windows command prompt

    type: cd \ and hit enter
    this will take you to C:\

    Now you need to navigate to your web root so....
    EG:
    Code:
    cd apache2triad\htdocs\
    Depending on what you have running - in this case I have apache2triad.

    Now you are in your web root, type:
    Code:
    convert -version

    Now that should spit out some text - on mine it says Invalid drive specification! This is because I dont have imagemagick on the works machine!!

    You should get something different, if you dont you will have to recheck your installation.

    I should be home in a few hours when I can get to my laptop which does have IM on it and help you from there.

    Keep trying
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's getting clearer! When I installed my server, I had set the "www" folder the same as the My Web Sites folder. Here's what I typed into the cmd.exe window:

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\>documents and settings/all users/documents/my documents/my web sites/ convert -version
    'documents' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>

    I don't think that cmd.exe can get to the convert -version command--it seems stopped at the very first word! Or am I misunderstanding what "root" means in this context? Has a step been left out?

    Thanks,
    Steve

  6. #6
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Imagick is an API for ImageMagick and currently all my examples are based on using the command line with php - basicly to run the examples on my site in windows and Linux you just need to remove the exec(" and "); from the example code.

    I have not looked into Imagick as it is something else to learn.

    The instructions you were looking at were for running ImageMagick from the command line of a windows PC.
    I did have some screen captures that I used to explain how to use ImageMagick on a windows XP machine; I will see if I can find them then add them to my instructions.

    To run on a server/website ( I use XAMPP on my windows PC ):

    php should find ImageMagick but you need to know the path to convert. Create this file and run as a normal php file on your server:
    PHP Code:

    <?php

    // Find out the path to ImageMagick
    // 2 different methods incase one does not work.

    echo "<pre>"
    system("type convert"); 
    echo 
    "</pre>"

    /*
    My output:
    convert is /usr/local/bin/convert
    */

    // Alternative method

    echo "<pre>"
    system('which convert',$path); print_r($path); 
    echo 
    "</pre>";

    /*
    My output:
    /usr/local/bin/convert 0
    */

    echo "<hr>"

    // Version installed
    echo "<pre>"
    exec("convert -version"); 
    echo 
    "</pre>";

    /*
    My output
    Version: ImageMagick 6.3.4 05/11/07 Q16 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC
    */
    ?>
    To do what you want with ImageMagick
    PHP Code:
    // exec("
    // pathto convert from the code above
    // Input image
    // Thumbnail operator you can use -resize instead
    // New size in this case it will maintain the width to height ratio
    // Image to save as can be a different format e.g gif or png
    // ");

    exec("convert tc5.jpg -thumbnail 100x100 thumbnail.jpg"); 

  7. #7
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This is getting a little clearer. My output was simply "1". I did not get a path to Imagick.

    For:

    // path to convert from the code above

    you would put for your computer:

    exec("convert /usr/local/bin/convert tc5.jpg -thumbnail 100x100 thumbnail.jpg");

    Is this right?

    Thanks,
    Steve

  8. #8
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    I am afraid 1 = fail

    I would say you have a problem with your installation. You should have had the path to convert displayed or the version details.

    PHP Code:
    //This is incorrect
    exec("convert /usr/local/bin/convert tc5.jpg -thumbnail 100x100 thumbnail.jpg"); 

    // This could be correct depending on the path but will not work anyway as you have an installation problem.
    exec("/usr/local/bin/convert tc5.jpg -thumbnail 100x100 thumbnail.jpg"); 
    On my windows PC.

    Go to start menu and select "Run"
    Type cmd in the run box press OK and you will get the "command screen" a black window.
    Type in cd\ and press the enter key and you shoul have c:\>
    Type in convert -version and press enter and you should get the version of ImageMagick installed.

  9. #9
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, I think I see the problem. I have Imagick installed and you are showing me how to work with ImageMagick. Are these two different programs?

    Thanks,
    Steve

  10. #10
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Yes they are different; Imagick as I said is an API for ImageMagick.

    Imagick will not as far as I know run without ImageMagick being installed as well. I have been trying to find a site I visited before with a lot more info on Imagick but can not find it.

    P.s. Here is the link I was looking for http://valokuva.org/?cat=1

    Imagick is a native php extension to create and modify images using the ImageMagick API.
    This extension requires ImageMagick version 6.2.4+ and PHP 5.1.3+
    So as I say to get Imagick working you need ImageMagick installed.

  11. #11
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think I see the problem. I did not follow this step:

    Next, launch your Visual Studio IDE and choose Open->Project. Select the configure workspace from the ImageMagick-6.?.?/VisualMagick/configure folder and press Open. Choose Build->Build Solution to compile the program and on completion run the program.

    If I don't have Visual Studio, how do I get Imagick to work? This seems to be an important step to skip!

    Thanks,
    Steve

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Steven, it might be easier to download the installer rather than the source code and try and compile it yourself.

    Download the exe from http://www.imagemagick.org/script/bi...es.php#windows and run the install program.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Wizard
    Join Date
    Feb 2007
    Location
    Southern California
    Posts
    1,340
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the link, Spike. I have it installed now. However, the instructions say:

    You have now installed ImageMagick. To test the installation select Command Prompt from the Windows Start menu. Within the window type:
    convert logo: logo.miff
    imdisplay logo.miff

    When I type "convert logo: logo.miff" and hit return, I get a flood of text, including version number "ImageMagick 6.3.6 10/11/07." How do I type in the second line for results? Typing it in after the results of the first line does not produce anything.

    Thanks,
    Steve


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •