Search code examples
phpimageimage-scalingimage-resizing

copy, resize, move image with php


I'm looking to copy, resize, and move an image. This is simular to how wordpress creates different sizes of the images when you upload. I want this to be executable without uploading anything just running when you run the page.

example:

$imagePath = 'http://example.com/images/myimageonserver.jpg';
$newImagePath = 'http://example.com/images/new/myimageonserver.jpg';
$newImageWidth = 300;
$newImageHeight = 200;

Does anyone know a script that will do this? Or some useful functions that can get this done.


Solution

  • I wrote this Class a while ago to wrap the GD library functions.

    You can call it like:

    $image = new Image('original/path/to.file', 'destination/of/resized.file');
    $image->resize(300, 200);
    $image->output();
    $image->clean();
    

    update:

    This class no longer functions as explained above.
    Here is a new example:

    $image = new Image();
    $image->source('original/path/to.file');
    $image->destination('destination/of/resized.file');
    $image->Manipulate->Resize(300,200);
    $image->output();
    $image->clean();