Skip to content

Instantly share code, notes, and snippets.

@6LYTH3
Created November 30, 2012 15:06

Revisions

  1. 6LYTH3 revised this gist Dec 2, 2012. 1 changed file with 61 additions and 0 deletions.
    61 changes: 61 additions & 0 deletions crop.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    <?php
    $image1 = 'data/album2/1.jpeg';
    $image2 = 'data/album1/2.jpeg';
    $image3 = 'data/album1/3.jpeg';
    $bg = 'images/11.jpg';

    $image1cre = imagecreatefromjpeg($image1);
    $image2cre = imagecreatefromjpeg($image2);
    $image3cre = imagecreatefromjpeg($image3);
    $ims = imagecreatefromjpeg($bg);

    $x = imagesx($image1cre);
    $y = imagesy($image1cre);

    $im = imagecreatetruecolor($y-300, $x);
    $im1 = imagecreatetruecolor($y, $x);
    $im2 = imagecreatetruecolor($y-200, $x);

    // Set the border and fill colors
    //$border = imagecolorallocate($im, 0, 0, 0);
    //$fill = imagecolorallocate($im, 255, 0, 0);

    $black = imagecolorallocate($im, 0, 0, 0);
    $white = imagecolorallocate($im, 255, 255, 255);

    $image1cre = imagerotate($image1cre, 90, 0);


    //list($width, $height) = getimagesize($image1);
    //$newWidth = $width * 0.5;
    //$newHeight = $height * 0.5;
    //$thumb = imagecreatetruecolor($newWidth, $newHeight);
    //imagecopyresized($thumb, $image1cre, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
    // Fill the selection
    //imagefilltoborder($thumb, 100, 100, $border, $fill);

    //$width_image = imagesx($image1cre);
    //$height_image = imagesy($image1cre);

    //imagefill($im,0,0,$black);

    imagecopy( $im1, $image1cre, 0, 0, 0, 0, $y-100, $x);

    $im1 = imagerotate($im1, 180, 0);
    imagecopy( $im2, $im1, 0, 0, 0, 0, $y-100, $x);
    //imagecopy( $im, $im1, 0, 0, 300, 300, 100, 300, 100);
    //imagecopymerge( $ims, $thumb, 10, $newHeight+500, 0, 0, $newWidth, $newHeight,100);

    //imagecopy($ims, $thumb, 10, 10, 20, 13, 300, 300);
    $im2 = imagerotate($im2, 180, 0);
    imagecopy( $im, $im2, 0, 0, 0, 0, $y-100, $x);
    $im = imagerotate($im, 270, 0);

    header('Content-Type: image/jpeg');
    imagejpeg($im);
    //imagejpeg($im, "images/image2.jpeg", 100);
    //imagejpeg($thumb);
    //imagedestroy($thumb);
    imagedestroy($im);

    ?>
  2. 6LYTH3 revised this gist Dec 1, 2012. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions merge.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php
    $image1 = 'data/album1/1.jpeg';
    $image2 = 'data/album1/2.jpeg';
    $image3 = 'data/album1/3.jpeg';

    $image1cre = imagecreatefromjpeg($image1);
    $image2cre = imagecreatefromjpeg($image2);
    $image3cre = imagecreatefromjpeg($image3);
    $im = imagecreate(1000, 1000);

    $black = imagecolorallocate($im, 0, 0, 0);
    $white = imagecolorallocate($im, 255, 255, 255);

    $width_image = imagesx($image1cre);
    $height_image = imagesy($image1cre);

    imagefill($im,0,0,$black);

    imagecopymerge( $im, $image1cre, 10, 10, 0, 0, $width_image, $height_image/2, 100);
    imagecopymerge( $im, $image2cre, 10, ($height_image/2)+50, 0, 0, $width_image, $height_image/2, 100);
    imagecopymerge( $im, $image3cre, 10, ($height_image/2)+($height_image/2)+100, 0, 0,$width_image, $height_image,100);

    header('Content-Type: image/png');
    imagejpeg($im);
    imagedestroy($im);

    ?>
  3. 6LYTH3 revised this gist Dec 1, 2012. 1 changed file with 32 additions and 0 deletions.
    32 changes: 32 additions & 0 deletions album.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    <?php
    $page = $_SERVER['PHP_SELF'];

    $column = 5;
    $base = "data";
    $thumbs = "thumbs";

    $get_album = $_GET['album'];

    if (!$get_album) {
    echo "<b>Select an album: </b><p />";
    $handle = opendir($base);
    while (($file = readdir($handle)) !== FALSE) {
    if (is_dir($base."/".$file) && $file != "." && $file != "..") {
    echo "<a href='$page?album=$file'>$file</a>"."<br>";
    }
    }
    }
    else{
    if (!is_dir($base."/".$get_album)) {
    echo "album doesnt exist.";
    }else{
    echo "<b>$get_album</b><p />";
    $handle = opendir($base."/".$get_album);
    while (($file = readdir($handle)) !== FALSE) {
    if ($file != "." && $file != "..") {
    echo "<img src='$base/$get_album/$file'><br>";
    }
    }
    }
    }
    ?>
  4. 6LYTH3 revised this gist Nov 30, 2012. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions multipleUpload.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php
    if (isset($_FILES['upload']) === true) {
    $file = $_FILES['upload'];

    for ($i = 0; $i < count($file['name']) ; $i++) {
    $file_name = $file['name'][$i];
    $file_tmp = $file['tmp_name'][$i];

    move_uploaded_file($file_tmp, 'images/'.$file_name);
    }
    }
    ?>

    <form action="" method="POST" enctype="multipart/form-data">
    <p>
    <input type="file" name="upload[]" multiple />
    <input type="submit" value="Upload"/>
    </p>
    </form>
  5. 6LYTH3 created this gist Nov 30, 2012.
    34 changes: 34 additions & 0 deletions upload.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    <?php
    if (isset($_FILES['image'])) {
    $errors = array();
    $allowed_ext = array('jpg','jpeg','png','gif');

    $file_name = $_FILES['image']['name'];
    $file_ext = strtolower(end(explode(".", $file_name)));
    $file_size = $_FILES['image']['size'];
    $file_tmp = $_FILES['image']['tmp_name'];

    if (in_array($file_ext, $allowed_ext) === false ) {
    $errors[] = 'Extenstion not allowed';
    }
    if ($file_size > 2097152) {
    $errors[] = 'File size must be under 2mb';
    }
    if (empty($errors)) {
    if(move_uploaded_file($file_tmp, 'images/'.$file_name)){
    echo "File Uploaded";
    }
    }else{
    foreach ($errors as $error) {
    echo $error , '<br>';
    }
    }
    }
    ?>

    <form action="" method="POST" enctype="multipart/form-data">
    <p>
    <input type="file" name="image" />
    <input type="submit" value="Upload"/>
    </p>
    </form>