Results 1 to 2 of 2

Thread: Image scaling with PHP?

  1. #1
    Join Date
    May 2009
    Posts
    130

    Question Image scaling with PHP?

    Is it possible to scale an image with PHP? I would like to create a script that automatically takes a huge .jpg image and turns it into a smaller, more easily loaded (no larger than 80-120k) image.

  2. #2
    Join Date
    May 2010
    Location
    Riverside, Ca
    Posts
    241
    yes, you have to use the gd library: http://us3.php.net/manual/en/ref.image.php

    Cited From: http://us3.php.net/manual/en/functio...opyresized.php
    PHP Code:
      <?php
    // File and new size
    $filename 'test.jpg';
    $percent 0.5;

    // Content type
    header('Content-type: image/jpeg'); // ADDED  BY ME: only if you don't want to save it for dynamic image creation only.(use: <img src="resizeimg.php?img=test.jpg" />)

    // Get new sizes
    list($width$height) = getimagesize($filename);
    $newwidth $width $percent;
    $newheight $height $percent;

    // Load
    $thumb imagecreatetruecolor($newwidth$newheight);
    $source imagecreatefromjpeg($filename);

    // Resize
    imagecopyresized($thumb$source0000$newwidth$newheight$width$height);

    // Output
    imagejpeg($thumb); // ADDED BY ME: for dynamic images, to save use imagejpeg($thumb, "folder/location/", 100);
    ?>
    "The generation of random numbers is too important to be left to chance."

Similar Threads

  1. PHP Image Upload with Flash Editing
    By oddball25 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 15 Dec 2009, 04:19 PM
  2. logo image not shown: PHP include relative root path?
    By web88js in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 04 Oct 2007, 05:36 PM
  3. Resizing an image through PHP
    By 0_o in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 16 Apr 2006, 05:26 PM

Posting Permissions

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