Example #1
0
                    $where1 = $wherefollow;
                }
                if ($where1 + 4 == $where2) {
                    $count++;
                }
                $str_loc = $where2 + 1;
            }
        }
    }
    if ($count > 1) {
        return true;
    } else {
        return false;
    }
}
if (isset($_SERVER['argv'][1])) {
    if ($_SERVER['argv'][1] == '-l') {
        $allfiles = glob('*.gif');
        foreach ($allfiles as $thisfile) {
            if (is_ani($thisfile)) {
                echo "{$thisfile} is animated\n";
            } else {
                echo "{$thisfile} is NOT animated\n";
            }
        }
    } else {
        if (file_exists($_SERVER['argv'][1])) {
            exit((int) is_ani($_SERVER['argv'][1]));
        }
    }
}
    //modify the $rss_item arry to add our own file name
    $rss_item['file_name'] = md5($rss_item['link']) . ".gif";
    //skip this item if it already exists in the database posted by this user
    $row = $Db->GetOne("SELECT id FROM items \n        WHERE \n        link = '" . mysql_real_escape_string($rss_item['link']) . "'\n        AND\n        dc_creator = '" . mysql_real_escape_string($rss_item['dc']['creator']) . "'");
    if ($row == '') {
        //download the image
        $ch = curl_init($rss_item['link']);
        $fp = fopen(IMAGE_TMP_DIR . "/" . $rss_item['file_name'], "w");
        curl_setopt($ch, CURLOPT_FILE, $fp);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $response = curl_exec($ch);
        curl_close($ch);
        //if the download was ok, then evaluate the gif
        if ($response) {
            //ignore if the file already exists or is not animated
            if (is_ani(IMAGE_TMP_DIR . "/" . $rss_item['file_name'])) {
                $animated_gifs[] = $rss_item;
            } else {
                unlink(IMAGE_TMP_DIR . "/" . $rss_item['file_name']);
            }
        } else {
            echo "Download failed for " . $rss_item['link'] . " response was " . $response . "";
        }
        fclose($fp);
    }
}
//insert new gifs into the amazon s3 bucket and the database
foreach ($animated_gifs as $this_gif) {
    //get the file hash
    $file_hash = md5_file(IMAGE_TMP_DIR . "/" . $this_gif['file_name']);
    //upload the image to s3 and return the s3 file name
Example #3
0
/**
 *	resize an image object
 *
 *	this function drops the reference to any currently resized version, 
 *	saves the resized image together with the original image in the page's 
 *	shared folder and updates the object file to use the resized version.
 *	@param array $args arguments
 *		key 'name' name of the objects
 *		key 'width' width in px
 *		key 'height' height in px
 *	@return array response
 *		true if the client is advised to reload the image, false if not
 */
function image_resize($args)
{
    // check for gd
    if (!_gd_available()) {
        return response('Host does not have gd', 500);
    }
    // set requested width & height
    if (($width = @intval($args['width'])) == 0) {
        return response('Required argument "width" is zero or does not exist', 400);
    }
    if (($height = @intval($args['height'])) == 0) {
        return response('Required argument "height" is zero or does not exist', 400);
    }
    load_modules('glue');
    // resolve symlinks
    $ret = object_get_symlink($args);
    if ($ret['#error']) {
        return $ret;
    } elseif ($ret['#data'] !== false) {
        log_msg('debug', 'image_resize: resolved object ' . quot($args['name']) . ' into ' . quot($ret['#data']));
        $args['name'] = $ret['#data'];
    }
    // load object
    $obj = load_object($args);
    if ($obj['#error']) {
        return $obj;
    } else {
        $obj = $obj['#data'];
    }
    if (@intval($obj['image-file-width']) == 0 || @intval($obj['image-file-height']) == 0) {
        return response('Original dimensions are not available', 500);
    }
    // set pagename
    $pn = array_shift(expl('.', $obj['name']));
    // resizing might not be necessary at all
    if (!empty($obj['image-resized-file']) && @intval($obj['image-resized-width']) == $width && @intval($obj['image-resized-height'] == $height)) {
        log_msg('debug', 'image_resize: width and height match the current resized file, no resize necessary');
        return response(false);
    }
    // else remove any currently resized file
    if (!empty($obj['image-resized-file'])) {
        log_msg('info', 'image_resize: dropping reference to previous resized file ' . quot($obj['image-resized-file']));
        delete_upload(array('pagename' => $pn, 'file' => $obj['image-resized-file'], 'max_cnt' => 1));
        unset($obj['image-resized-file']);
        unset($obj['image-resized-width']);
        unset($obj['image-resized-height']);
        // update object file as well
        $ret = object_remove_attr(array('name' => $obj['name'], 'attr' => array('image-resized-file', 'image-resized-width', 'image-resized-height')));
        if ($ret['#error']) {
            return $ret;
        }
        $was_resized = true;
    } else {
        $was_resized = false;
    }
    // check if width or height are larger than the original
    if (@intval($obj['image-file-width']) <= $width || @intval($obj['image-file-height']) <= $height) {
        log_msg('debug', 'image_resize: dimensions requested are larger or equal than the original file is, no resize necessary');
        // the client need not reload the the image if we were using the
        // original before
        if (!$was_resized) {
            return response(false);
        } else {
            return response(true);
        }
    }
    // check if we really have a source image
    if (empty($obj['image-file-mime']) && empty($obj['image-file'])) {
        return response(false);
    }
    // TODO (later): make this a generic function
    // load source file
    $ext = filext($obj['image-file']);
    $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $obj['image-file'];
    if ($obj['image-file-mime'] == 'image/jpeg' || in_array($ext, array('jpg', 'jpeg'))) {
        $orig = @imagecreatefromjpeg($fn);
        $dest_ext = 'jpg';
    } elseif ($obj['image-file-mime'] == 'image/png' || $ext == 'png') {
        $orig = @imagecreatefrompng($fn);
        $dest_ext = 'png';
    } elseif (is_ani($fn)) {
        // animated images shall not be resized
        log_msg('debug', 'image_resize: animated image, not resizing');
        return response(true);
    } elseif ($obj['image-file-mime'] == 'image/gif' || $ext == 'gif') {
        $orig = @imagecreatefromgif($fn);
        // save gifs as png
        // TODO (later): check for animated gif (see php.net/manual/en/function.imagecreatefromgif.php)
        $dest_ext = 'png';
    } else {
        return response('Unsupported source file format ' . quot($obj['image-file']), 500);
    }
    if ($orig === false) {
        return response('Error loading source file ' . quot($obj['image-file']), 500);
    }
    // get source file dimensions
    $orig_size = @getimagesize($fn);
    // create resized image
    if (($resized = @imagecreatetruecolor($width, $height)) === false) {
        @imagedestroy($orig);
        return response('Error creating the resized image', 500);
    }
    // preserve any alpha channel
    @imagealphablending($resized, false);
    @imagesavealpha($resized, true);
    // try to resize
    if (!@imagecopyresampled($resized, $orig, 0, 0, 0, 0, $width, $height, $orig_size[0], $orig_size[1])) {
        @imagedestroy($resized);
        @imagedestroy($orig);
        return response('Error resizing the source image', 500);
    }
    // setup destination filename
    $a = expl('.', $obj['image-file']);
    if (1 < count($a)) {
        // throw the previous extension away
        $fn = CONTENT_DIR . '/' . $pn . '/shared/' . implode('.', array_slice($a, 0, -1)) . '-' . $width . 'x' . $height . '.' . $dest_ext;
    } else {
        $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $a[0] . '-' . $width . 'x' . $height . '.' . $dest_ext;
    }
    $m = umask(0111);
    if ($dest_ext == 'jpg') {
        $ret = @imagejpeg($resized, $fn, IMAGE_JPEG_QUAL);
    } else {
        if ($dest_ext == 'png') {
            // preserve any alpha channel
            @imagealphablending($resized, false);
            @imagesavealpha($resized, true);
            $ret = @imagepng($resized, $fn, IMAGE_PNG_QUAL);
        }
    }
    umask($m);
    // destroy images again
    @imagedestroy($resized);
    @imagedestroy($orig);
    if (!$ret) {
        return response('Error saving the resized image', 500);
    } else {
        log_msg('info', 'image_resize: created a resized image of ' . quot($obj['name']) . ' -> ' . quot(basename($fn)));
    }
    // the code above can take a while, so read in the object anew via
    // update_object()
    $update = array();
    $update['name'] = $obj['name'];
    $update['image-resized-file'] = basename($fn);
    $update['image-resized-width'] = $width;
    $update['image-resized-height'] = $height;
    // we change width and height here as well since we are racing with the
    // save_object from the frontend after resize
    $update['object-width'] = $width . 'px';
    $update['object-height'] = $height . 'px';
    return update_object($update);
}
Example #4
0
 $size = $_FILES['upload']['size'];
 if (strlen($name)) {
     $ext = strtolower(file_extension($name));
     if (in_array($ext, $valid_formats)) {
         if ($size < $max_upload) {
             $actual_image_name = time() . mt_rand() . "." . $ext;
             if ($vbulletin->options['safeupload']) {
                 $tmpdir = $vbulletin->options['tmppath'];
             } else {
                 $tmpdir = sys_get_temp_dir();
             }
             $uploaded = $tmpdir . DIRECTORY_SEPARATOR . $actual_image_name;
             move_uploaded_file($_FILES["upload"]["tmp_name"], $uploaded);
             // ACP-511
             //is this an animated gif?
             if (is_ani($uploaded)) {
                 if ($allowanimation) {
                     // animated image and animation allowed
                 } else {
                     //animated image and animation disallowed
                     @unlink($upload);
                     $error = true;
                     $message = "You may not upload animated images";
                 }
             } else {
                 //we're OK it's not animated
             }
         } else {
             $error = true;
             $message = "Image size too large";
         }