Example #1
1
 public static function UploadImage($photo)
 {
     $db = DB::getInstance();
     if ($photo['name']) {
         if (!$photo['error']) {
             // Fullsize image
             $data = file_get_contents($photo["tmp_name"]);
             $name = $photo['name'];
             $source = 'uploads/' . $name;
             $thumbSource = 'uploads/thumbnail_' . $name;
             move_uploaded_file($photo['tmp_name'], $source);
             $size = getimagesize($source);
             // Thumbnail
             smart_resize_image(null, $data, 400, 400, true, $thumbSource, false, false, 75);
             // Base64
             $miniblob = smart_resize_image(null, $data, 35, 35, true, "return", false, false, 1);
             ob_start();
             imagejpeg($miniblob, null, 15);
             $blobData = ob_get_contents();
             ob_end_clean();
             $base64 = 'data:image/image/jpeg' . ';base64,' . base64_encode($blobData);
             // Insert data to DB
             $insertImage = DB::getInstance()->insert("pictures", array("id" => null, "name" => $name, "source" => $source, "thumb" => $thumbSource, "base64" => $base64, "width" => $size[0], "height" => $size[1]));
         }
     }
 }
Example #2
1
 public function upload($article_id)
 {
     $accessToken = Yii::$app->params['accessToken'];
     $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     if ($this->validate()) {
         $image_name = Yii::$app->security->generateRandomString();
         $this->file->saveAs('uploads/' . $image_name . '.' . $this->file->extension);
         $file_name = 'uploads/' . $image_name . '.' . $this->file->extension;
         $f = fopen("{$file_name}", "rb");
         $result = $dbxClient->uploadFile("/{$image_name}" . '.' . $this->file->extension, dbx\WriteMode::add(), $f);
         fclose($f);
         $src = $dbxClient->createShareableLink($result['path']);
         $src[strlen($src) - 1] = '1';
         $image = new Image();
         $image->image_name = $image_name . '.' . $this->file->extension;
         $image->image_article = $article_id;
         $image->image_src_big = $src;
         //small
         $file_name = 'uploads/' . $image_name . '.' . $this->file->extension;
         $resizedFile = 'uploads/small_' . $image_name . '.' . $this->file->extension;
         smart_resize_image($file_name, null, 0, 100, true, $resizedFile, false, false, 100);
         $f = fopen("{$resizedFile}", "rb");
         $result = $dbxClient->uploadFile("/small_" . "{$image_name}" . '.' . $this->file->extension, dbx\WriteMode::add(), $f);
         fclose($f);
         $src = $dbxClient->createShareableLink($result['path']);
         $src[strlen($src) - 1] = '1';
         $image->image_src_small = $src;
         $image->save();
         unlink($file_name);
         unlink($resizedFile);
         return true;
     } else {
         return false;
     }
 }
Example #3
1
    //this is the directory where your files will be stored
    if ($filetype == "image") {
        $file_uploader->addAllowedFileType(array('.jpeg', '.jpg', '.gif', '.png'));
    } else {
        $file_uploader->addAllowedFileType(array('.doc', '.docx', '.pdf', '.xls', '.xlsx', '.txt', '.rtf', '.zip'));
    }
    try {
        $filename = $file_uploader->uploadFile('image');
        if ($filename) {
            list($name_file, $ext) = split('[.]', $filename);
            //resize if its an image
            if ($ext == 'jpeg' || $ext == 'jpg' || $ext == 'gif' || $ext == 'png') {
                $image_src = "files_uploaded/" . stripslashes($filename);
                $image_size = getimagesize($image_src);
                if ($image_size[0] > $max_size) {
                    smart_resize_image($image_src, $image_src, $max_size, 0, true, 'file', false, false);
                }
            }
            $http_server = "http://scaredrabbit.net/jot/";
            //full URL - http://yourwebsite.com/
            $file_path = $http_server . "files_uploaded/" . $filename;
            $data = array('new_file' => $file_path, 'file_description' => $description, 'file_type' => $filetype, 'error_msg' => '');
        } else {
            $data = array('error_msg' => 'No file found.');
        }
    } catch (Exception $e) {
        $data = array('error_msg' => $e->getMessage());
    }
} else {
    $data = array('error_msg' => 'Upload error occurred. Try again.');
}
function resize_image($file, $filename, $w, $h, $crop = FALSE)
{
    list($width, $height) = getimagesize($file);
    // echo $filename;
    $r = $width / $height;
    // echo $width.' -- '.$height." == $r <br>";
    if ($crop) {
        if ($width > $height) {
            $width = ceil($width - $width * abs($r - $w / $h));
        } else {
            $height = ceil($height - $height * abs($r - $w / $h));
        }
        $newwidth = $w;
        $newheight = $h;
    } else {
        if ($w / $h > $r) {
            $newwidth = $h * $r;
            $newheight = $h;
        } else {
            $newheight = $w / $r;
            $newwidth = $w;
        }
    }
    //        echo "$newwidth -- $newheight <br>";
    $resizedFile = 'img_packing/' . $filename;
    //call the function (when passing path to pic)
    $img = smart_resize_image($file, null, $newwidth, $newheight, TRUE, $resizedFile, false, false, 100);
    //call the function (when passing pic as string)
    //        $img = smart_resize_image(null, file_get_contents($file), $newwidth, $newheight, true, $resizedFile, false, false, 100);
    //    $src = imagecreatefromjpeg($file);
    //    echo $src;
    //    $dst = imagecreatetruecolor($newwidth, $newheight);
    //    imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    return $img;
}
function parse_and_write($url)
{
    $json = file_get_contents($url);
    $apps = json_decode($json);
    $conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
    foreach ($apps->{'feed'}->{'entry'} as $app) {
        $id = (int) $app->{'id'}->{'attributes'}->{'im:id'};
        $sql = "SET NAMES utf8;SELECT * FROM main WHERE id=:ID";
        $st = $conn->prepare($sql);
        $st->bindValue(":ID", $id, PDO::PARAM_INT);
        $st->execute();
        $row = $st->fetch();
        if (!$row) {
            $id = $app->{'id'}->{'attributes'}->{'im:id'};
            $name = $app->{'im:name'}->{'label'};
            $app_url = $app->{'id'}->{'label'};
            $price = $app->{'im:price'}->{'attributes'}->{'amount'};
            $price_date = time();
            $category = $app->{'category'}->{'attributes'}->{'label'};
            $show = 1;
            $icon_url = $app->{'im:image'}[1]->{'label'};
            $dir = "icons";
            // Full Path
            $filename = $id . '.png';
            is_dir($dir) || @mkdir($dir) || die("Can't Create folder");
            copy($icon_url, $dir . DIRECTORY_SEPARATOR . $filename);
            smart_resize_image($dir . "/" . $filename, null, 65, 65, false, $dir . "/" . $filename, false, false, 100);
            $Sql = "INSERT IGNORE INTO main (id, name, app_url, price, price_date, category, output, icon_url) VALUES (:ID, :NAME, :APP_URL, :PRICE, :PRICE_DATE, :CATEGORY, :SHOW, :ICON_URL)";
            $St = $conn->prepare($Sql);
            $St->bindValue(":ID", $id, PDO::PARAM_INT);
            $St->bindValue(":NAME", $name, PDO::PARAM_STR);
            $St->bindValue(":APP_URL", $app_url, PDO::PARAM_STR);
            $St->bindValue(":PRICE", $price);
            $St->bindValue(":PRICE_DATE", $price_date, PDO::PARAM_INT);
            $St->bindValue(":CATEGORY", $category, PDO::PARAM_STR);
            $St->bindValue(":SHOW", $show, PDO::PARAM_INT);
            $St->bindValue(":ICON_URL", $_SERVER['HTTP_HOST'] . "/parser/icons/" . $filename, PDO::PARAM_STR);
            $St->execute();
        }
    }
    $conn = null;
}
Example #6
0
function merge($width, $height)
{
    $nowtime = time();
    $array_variable = get_variable();
    $bg = $array_variable[0];
    $over = $array_variable[1];
    $outputFile = $array_variable[2];
    $result = $array_variable[3];
    $path_to_save = $array_variable[4];
    $n = $array_variable[5];
    $tmp_img_rezized = $path_to_save . "/tmp_" . $nowtime . ".jpg";
    $tmp_img = $path_to_save . "/tmp_" . $n . ".png";
    // $result_jpg_compressed = $path_to_save.'/'.$n.'.JPG';
    // resize_image
    // $bg = resize_image($bg, $width, $width);
    smart_resize_image($bg, null, $width, $height, false, $tmp_img_rezized, true);
    // $base_image = imagecreatefrompng($bg);
    // $bg = $tmp_img_rezized;
    // jpg2png($bg, $outputFile);
    jpg2png($tmp_img_rezized, $outputFile);
    $base_image = imagecreatefrompng($outputFile);
    $top_image = imagecreatefrompng($over);
    // $merged_image = $result;
    imagesavealpha($top_image, true);
    imagealphablending($top_image, true);
    imagecopy($base_image, $top_image, 0, 0, 0, 0, $width, $height);
    imagepng($base_image, $result);
    // rename to temp for compression
    rename($result, $path_to_save . "/tmp_" . $n . ".png");
    // compress IMG
    $img = imagecreatefrompng($tmp_img);
    // imagejpeg($img,$result_jpg_compressed,75);
    imagejpeg($img, $result, 75);
    unlink($tmp_img);
    unlink($tmp_img_rezized);
    // if necessery !!!!!!!!!!!!!!!!!!!
    //unlink($outputFile);
    //unlink($over);
}
Example #7
0
function rep_add_custom_fields($id)
{
    global $post, $plugin_url, $rep_is_listing, $rep_private, $rep_listings_fields, $rep_listings_vars, $rep_dir, $rep_post_hash, $rep_upload_dir, $maximages;
    foreach ($rep_listings_fields as $k) {
        $rep_listings_vars[$k] = trim(stripslashes(!empty($_POST[$k])));
    }
    if ($rep_is_listing == 1) {
        delete_post_meta($id, 'rep_islisting');
        add_post_meta($id, 'rep_islisting', 1);
        delete_post_meta($id, 'rep_post_hash');
        $rep_post_hash = trim(stripslashes($_POST['rep_post_hash']));
        add_post_meta($id, 'rep_post_hash', $rep_post_hash);
        delete_post_meta($id, 'rep_private');
        add_post_meta($id, 'rep_private', $_POST['rep_private']);
        foreach ($rep_listings_vars as $k => $v) {
            if (!stristr($k, 'image')) {
                delete_post_meta($id, 'rep_' . $k);
                if ($v) {
                    if ($k == 'listing' || $k == 'property') {
                        if (is_array($_POST[$k])) {
                            $cbvals = @implode(',', $_POST[$k]);
                        } else {
                            $cbvals = $v;
                        }
                    } else {
                        $cbvals = $v;
                    }
                    add_post_meta($id, 'rep_' . $k, $cbvals);
                }
            }
        }
        if (!current_user_can('upload_files')) {
            wp_die(esc_attr('You do not have permission to upload files.'));
        }
        for ($i = 1; $i < 21; $i++) {
            $imagekey = "image_{$i}";
            $image = $_FILES[$imagekey]['name'];
            $imagealtkey = "image_alt_{$i}";
            $imagealt = $rep_listings_vars[$imagealtkey];
            $deleteimage = "del_{$imagekey}";
            delete_post_meta($id, 'rep_' . $imagealtkey);
            if ($imagealt != '') {
                add_post_meta($id, 'rep_' . $imagealtkey, $imagealt);
            }
            $ft = strtolower($image);
            preg_match('/(.*)\\.(.*)/', $ft, $matches);
            $extension = $matches[2];
            $filetypes = array('jpg', 'jpeg', 'bmp', 'gif', 'png');
            $error = '';
            if (!file_exists($rep_dir) && @(!mkdir($rep_dir, 0777))) {
                $error = sprintf(esc_attr("The userphoto upload content directory does not exist and could not be created. Please ensure that you have write permissions for the '%s' directory. Did you put slash at the beginning of the upload path in Misc. settings? It should be a path relative to the WordPress root directory. <code>wp_upload_dir()</code> returned:<br /> <code style='white-space:pre'>%s</code>", 'user-photo'), $rep_dir, print_r($rep_upload_dir, true));
            }
            $oldimage = get_post_meta($id, 'rep_' . $imagekey, true);
            $oldimage = $_POST[$deleteimage];
            if (!$error && in_array($extension, $filetypes) && $_FILES[$imagekey]['error'] === 0) {
                delete_post_meta($id, 'rep_' . $imagekey);
                $tmpimg = "{$rep_post_hash}{$imagekey}.{$extension}";
                $imagepath = "{$rep_dir}/{$tmpimg}";
                move_uploaded_file($_FILES[$imagekey]['tmp_name'], $imagepath);
                if (file_exists($imagepath)) {
                    smart_resize_image($imagepath, 300, 300, true, "{$rep_dir}/thumb_{$tmpimg}", false, false);
                }
                add_post_meta($id, 'rep_' . $imagekey, $tmpimg);
            } elseif (!$error && $_POST[$deleteimage] != '') {
                delete_post_meta($id, 'rep_' . $imagekey);
                @unlink("{$rep_dir}/{$oldimage}");
                @unlink("{$rep_dir}/thumb_{$oldimage}");
            }
        }
    } elseif (isset($_POST['islisting']) && $_POST['islisting'] != 1) {
        delete_post_meta($id, 'rep_islisting');
    }
}
function scrape_asins($asin)
{
    $result = array();
    $url = "http://www.amazon.com/dp/" . $asin;
    $data = postForm($url);
    //echo $data;die;
    $html = str_get_html($data);
    foreach ($html->find('h1[id=title] span[id=productTitle]') as $title) {
        $result['title'] = $title->plaintext;
        break;
    }
    //echo $result['title'];die;
    $result['asin'] = $asin;
    $result['description'] = "";
    $htmldesc = file_get_html($url);
    foreach ($htmldesc->find('div[class=productDescriptionWrapper]') as $description) {
        $result['description'] = $description->plaintext;
        break;
    }
    $result['brand'] = "";
    foreach ($html->find('a[id=brand]') as $brand) {
        $result['brand'] = $brand->plaintext;
        break;
    }
    $result['features'] = "";
    foreach ($html->find('div[id=feature-bullets] ul[class=a-vertical a-spacing-none]') as $features) {
        foreach ($features->find('li span') as $features_lines) {
            $result['features'] .= '<li>' . $features_lines->plaintext . '</li>';
        }
        break;
    }
    $result['imageurl'] = "";
    foreach ($html->find('div[id=imgTagWrapperId] img') as $image) {
        $result['imageurl'] = $image->src;
        break;
    }
    $result['imageurl'] = str_replace("._SY300_", "", $result['imageurl']);
    $size = getimagesize($result['imageurl']);
    $height = $size[1];
    $width = $size[0];
    if ($size[1] < 500) {
        $diff = 500 - $size[1];
        $height = $size[1] + $diff;
        $width = $size[0] + $diff;
    }
    $url = $result['imageurl'];
    $extension_upload = strtolower(substr(strrchr($result['imageurl'], '.'), 1));
    $savedpict = 'uploads/amazon/' . $asin . '.' . $extension_upload;
    touch($savedpict);
    chmod($savedpict, 0777);
    $img = $savedpict;
    file_put_contents($img, file_get_contents($url));
    /* $thumb = new Imagick($img);
         
    $thumb->resizeImage(800,800,Imagick::FILTER_LANCZOS,1);
    
    $thumb->writeImage($img);
    
    $thumb->destroy();*/
    smart_resize_image($img, null, $width, $height, false, $img, false, false, 100);
    $result['imageurl'] = 'http://ezon.org/cl/ezonlister/' . $img;
    //http://ecx.images-amazon.com/images/I/61bfvPIbrdL._SX700_.jpg
    //$result['imageurl']=str_replace('SY300','SS700',$result['imageurl']);
    //echo $result['imageurl'];die;
    $result['listprice'] = "";
    foreach ($html->find('div[id=price] table[class=a-lineitem] td[class=a-span12 a-color-secondary a-size-base a-text-strike]') as $listprice) {
        $result['listprice'] = $listprice->plaintext;
        break;
    }
    $url = "http://www.amazon.com/gp/offer-listing/" . $asin . "/ref=dp_olp_new?ie=UTF8&condition=new";
    $data = postForm($url);
    $htmloffer = str_get_html($data);
    $result['offerprice'] = "";
    $result['prime'] = "";
    $prime = 0;
    $etat = 0;
    foreach ($htmloffer->find('div[class=a-section a-spacing-double-large]') as $html1) {
        foreach ($html1->find('div[class=a-row a-spacing-mini olpOffer]') as $html2) {
            foreach ($html2->find('div[class=a-column a-span2]') as $html3) {
                foreach ($html3->find('span[class=a-size-large a-color-price olpOfferPrice a-text-bold]') as $html4) {
                    $price = $html4->plaintext;
                }
                foreach ($html3->find('span[class=supersaver]') as $html6) {
                    $etat++;
                    $prime = 1;
                    if ($etat <= 1) {
                        $lowestprice = $price;
                    }
                }
            }
        }
    }
    $result['offerprice'] = $price;
    if ($prime > 0) {
        $result['offerprice'] = $lowestprice;
        $result['prime'] = 'Yes';
    }
    $result['quantity'] = "";
    $qte = 0;
    foreach ($html->find('select[id=quantity]') as $quantity) {
        foreach ($quantity->find('option') as $opt) {
            $qte++;
        }
    }
    $result['quantity'] = $qte;
    $result['shippingprice'] = "";
    foreach ($html->find('div[id=price] table[class=a-lineitem] tr td[class=a-span12] span[id=ourprice_shippingmessage] span[class=a-size-base a-color-secondary]') as $shippingprice) {
        $result['shippingprice'] = $shippingprice->plaintext;
        break;
    }
    $result['weight'] = "";
    foreach ($html->find('div[id=detail-bullets] td[class=bucket] div[class=content] ul') as $details) {
        foreach ($details->find('li') as $weight) {
            if (strpos($weight->plaintext, 'Weight')) {
                $result['weight'] = $weight->plaintext;
                break;
            }
        }
    }
    $str = $result['weight'];
    preg_match_all('!\\d+!', $str, $matches);
    $pos1 = strpos($result['weight'], $matches[0][0]);
    $pos2 = strpos($result['weight'], '(');
    $pound = substr($result['weight'], $pos1 + strlen($matches[0][0]), $pos2 - 18);
    $result['weight'] = $matches[0][0] . ' ' . $pound;
    $result['dimension'] = "";
    foreach ($html->find('div[id=detail-bullets] td[class=bucket] div[class=content] ul') as $details) {
        foreach ($details->find('li') as $dimension) {
            if (strpos($dimension->plaintext, 'Dimensions')) {
                $result['dimension'] = $dimension->plaintext;
                break;
            }
        }
    }
    $pos1 = strpos($result['dimension'], ':');
    //$pos2=strpos($result['dimension'],'inches');
    $dimension = substr($result['dimension'], $pos1 + 1, strlen($result['dimension']));
    $dimension = str_replace('inches', '', $dimension);
    $result['dimension'] = $dimension;
    $result['mpn'] = "";
    foreach ($html->find('div[id=detail-bullets] td[class=bucket] div[class=content] ul') as $details) {
        foreach ($details->find('li') as $mpn) {
            if (strpos($mpn->plaintext, 'model')) {
                $result['mpn'] = $mpn->plaintext;
                break;
            }
        }
    }
    $pos1 = strpos($result['mpn'], ':');
    $mpn = substr($result['mpn'], $pos1 + 1, strlen($result['mpn']));
    $result['mpn'] = $mpn;
    $i = 0;
    $result['pictures'] = "";
    $pictures = array();
    foreach ($html->find('div[id=altImages] ul') as $blocthumb) {
        foreach ($blocthumb->find('li img') as $liimg) {
            $result['pictures' . $i] = $liimg->src;
            $result['pictures' . $i] = str_replace('SS40', 'SS400', $result['pictures' . $i]);
            $i++;
        }
    }
    $j = 0;
    while (isset($result['pictures' . $j])) {
        $pictures[] = $result['pictures' . $j];
        $j++;
    }
    $thumbpictures = "";
    if (count($pictures) > 0) {
        $thumbpictures = implode(',', $pictures);
    }
    $result['pictures'] = $thumbpictures;
    return $result;
}
Example #9
0
    $selectedImage = $images["photo"][$rndID];
    $selectedImage["url"] = getImageURL($selectedImage, $w, $h);
    $selectedImage["licensename"] = getImageLicense($selectedImage);
    $selectedImage["fulltitle"] = $selectedImage["title"] . " by " . $selectedImage["ownername"];
}
if (!isset($selectedImage)) {
    $selectedImage["url"] = $site["flickr"]["defaultImage"];
    $selectedImage["licensename"] = $site["flickr"]["defaultLicense"];
    $selectedImage["fulltitle"] = $site["flickr"]["defaultFullTitle"];
}
$selectedImage["md5"] = md5($selectedImage["url"]);
$selectedImage["cached"] = $site["imageCache"] . $selectedImage["md5"] . ".jpg";
$selectedImage["cachedresized"] = $site["path"] . $site["folder"] . $site["imageCache"] . $selectedImage["md5"] . "." . $w . "." . $h . ".jpg";
$selectedImage["cachedresizedpublic"] = $site["folder"] . $site["imageCache"] . $selectedImage["md5"] . "." . $w . "." . $h . ".jpg";
cacheImage($selectedImage["url"], $selectedImage["cached"]);
smart_resize_image($selectedImage["cached"], null, $w, $h, false, $selectedImage["cachedresized"], true);
//Convert image to jpg
$img = $selectedImage["cachedresized"];
$img_info = getimagesize($img);
$width = $img_info[0];
$height = $img_info[1];
$convert = false;
switch ($img_info[2]) {
    case IMAGETYPE_GIF:
        $src = imagecreatefromgif($img);
        $convert = true;
        break;
    case IMAGETYPE_PNG:
        $src = imagecreatefrompng($img);
        $convert = true;
        break;
Example #10
0
include_once 'core/util.php';
$cachedir = "cache/images/";
$source = "images/" . GETSafe('img');
$x = GETSafe('x');
$y = GETSafe('y');
$cachefile = md5($source . $x . $y);
$path = pathinfo($source);
$ext = strtolower($path["extension"]);
if (!$source || !$x || !$y) {
    die("Missing Params");
}
if (!file_exists($cachedir . $cachefile)) {
    if (!is_dir($cachedir)) {
        mkdir($cachedir, 0777);
    }
    smart_resize_image($source, $x, $y, false, $cachedir . $cachefile, false, false);
}
$im = file_get_contents($cachedir . $cachefile);
header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime("+20 week")) . 'GMT');
switch ($ext) {
    case "jpeg":
    case "jpg":
        header('Content-type: image/jpeg');
        header('Content-transfer-encoding: binary');
        break;
    case "gif":
        header('Content-type: image/gif');
        header('Content-transfer-encoding: binary');
        break;
    case "png":
        header('Content-type: image/png');
Example #11
0
 /**
  * Eine Datei direkt vom Dateisystem zu holen. Bei $echo true wird diese direkt zurückgegeben
  * was beim "File Request" benutzt wird. Wenn $echo false ist wird der Inhalt der Datei
  * zurückgegeben. Der $file wird in allen "Roots" gesucht, daher darf kein absoluter Dateiname
  * angegeben werden, wie bei allen RapiDev Funktionalitüten mit Dateinamen.
  * 
  * TODO: Innen drin werden derzeit noch ein paar Austauschungen gemacht in JavaScripts,
  *       dafür sollte ein System entwickelt werden womit der User Funktionen dafür ablegen
  *       kann.
  *
  * @param String $file
  * @param Bool   $echo
  */
 protected function FetchFile($file, $echo = true)
 {
     RDD::Log('FetchFile of ' . $file, TRACE, 1500);
     if (strpos($file, "?") !== false) {
         $urlparts = explode("?", $file);
         $file = $urlparts[0];
         if (isset($urlparts[1])) {
             $param = $urlparts[1];
         }
     }
     $fileparts = explode('/', $file);
     foreach ($fileparts as $filepart) {
         if (strpos($filepart, '..') !== false) {
             throw new RDE('RD: access denied to relative parts in directory structure');
         }
     }
     if (isset($param)) {
         if (strpos($param, 'x') !== false && strpos($param, '&') === false) {
             $xy = explode('x', $param);
             $x = $xy[0] + 0;
             $y = 0;
             if (isset($xy[1])) {
                 $y = $xy[1] + 0;
             }
             $resize = true;
             /* $lastone = $fileparts[count($fileparts)-1];
             			$lastfour = substr($lastone,-4);
             			if ($lastfour == '.jpg') {
             				$fileparts[count($fileparts)-1] = substr($lastone,0,-4);
             				$resize = true;
             			} */
         }
     }
     if (in_array($fileparts[0], array_keys($this->PublicDirs)) || file_exists($_SERVER['DOCUMENT_ROOT'] . DIR_SEP . implode(DIR_SEP, $fileparts))) {
         foreach ($this->PublicDirs as $From => $To) {
             if ($fileparts[0] == $From || file_exists($_SERVER['DOCUMENT_ROOT'] . DIR_SEP . implode(DIR_SEP, $fileparts))) {
                 if (file_exists($_SERVER['DOCUMENT_ROOT'] . DIR_SEP . implode(DIR_SEP, $fileparts))) {
                     $Filename = $_SERVER['DOCUMENT_ROOT'] . DIR_SEP . implode(DIR_SEP, $fileparts);
                 } else {
                     $fileparts[0] = $To;
                     $Filename = $this->File(implode(DIR_SEP, $fileparts));
                 }
                 if (!$Filename) {
                     RDD::Log("cant find file " . implode(DIR_SEP, $fileparts));
                     exit(0);
                 }
                 header('Last-Modified: ' . date("r", filemtime($Filename)));
                 $this->RequireOnceFile('functions/get_mime_type.php');
                 $this->RequireOnceFile('functions/smart_image_resize.php');
                 $mime_type = get_mime_type($Filename);
                 if (!$mime_type) {
                     $mime_type = 'text/plain';
                 }
                 if (strpos($mime_type, 'x-httpd-php') !== false) {
                     include $Filename;
                 } else {
                     if (isset($resize)) {
                         /* $filemd5 = md5_file($Filename);
                         			$firsttwo = substr($filemd5,0,2);
                         			$rest = substr($filemd5,2);
                         			if (!is_dir($this->CacheDir.DIR_SEP.'resizecache')) {
                         				mkdir($this->CacheDir.DIR_SEP.'resizecache');
                         				chmod($this->CacheDir.DIR_SEP.'resizecache',777);
                         			}
                         			if (!is_dir($this->CacheDir.DIR_SEP.'resizecache'.DIR_SEP.$firsttwo)) {
                         				mkdir($this->CacheDir.DIR_SEP.'resizecache'.DIR_SEP.$firsttwo);
                         				chmod($this->CacheDir.DIR_SEP.'resizecache'.DIR_SEP.$firsttwo,777);
                         			} */
                         smart_resize_image($Filename, $x, $y, true, 'browser');
                     } else {
                         header('Content-type: ' . $mime_type);
                         readfile($Filename);
                     }
                 }
                 exit(0);
             }
         }
     } else {
         throw new RDE('RD: access denied to this file');
     }
 }
Example #12
0
function resizeimage($source, $x, $y)
{
    $cachedir = "cache/images/";
    $path = pathinfo($source);
    $ext = strtolower($path["extension"]);
    $cachefile = md5($source . $x . $y) . '.' . $ext;
    if (!file_exists($cachedir . $cachefile)) {
        if (!is_dir($cachedir)) {
            mkdir($cachedir, 0777);
        }
        smart_resize_image($source, $x, $y, false, $cachedir . $cachefile, false, false);
    }
    return Config::$webPath . "cache/images/" . $cachefile;
}
<?php

$filename = $_GET['filename'];
$new_width = $_GET['w'];
$new_height = $_GET['h'];
$new_compression = $_GET['c'];
echo smart_resize_image($filename, $new_width, $new_height, true, 'browser', false, false);
function smart_resize_image($file, $width = 0, $height = 0, $proportional = false, $output = 'file', $delete_original = true, $use_linux_commands = false)
{
    if ($height <= 0 && $width <= 0) {
        return false;
    }
    # Setting defaults and meta
    $info = getimagesize($file);
    $image = '';
    $final_width = 0;
    $final_height = 0;
    list($width_old, $height_old) = $info;
    # Calculating proportionality
    if ($proportional) {
        if ($width == 0) {
            $factor = $height / $height_old;
        } elseif ($height == 0) {
            $factor = $width / $width_old;
        } else {
            $factor = min($width / $width_old, $height / $height_old);
        }
        $final_width = round($width_old * $factor);
        $final_height = round($height_old * $factor);
    } else {
        $final_width = $width <= 0 ? $width_old : $width;
function smartImageResize($width, $initImg, $resImg)
{
    include_once 'eg_image_smart_resize.php';
    smart_resize_image($initImg, $width, 0, true, $resImg, false);
}
Example #15
0
function resizeImage($origName, $destName, $maxWidth = false, $maxHeight = false, $quality = false)
{
    //http://php.net/manual/en/function.imagecopyresampled.php
    if (!$maxWidth) {
        $maxWidth = bu::config('rc/maxWidth');
    }
    if (!$maxHeight) {
        $maxHeight = bu::config('rc/maxHeight');
    }
    if (!$quality) {
        $quality = bu::config('rc/quality');
    }
    $width = $maxWidth;
    $height = $maxHeight;
    list($width_orig, $height_orig) = getimagesize($origName);
    $ratio_orig = $width_orig / $height_orig;
    if ($width_orig < $width and $height_orig < $height) {
        $width = $width_orig;
        $height = $height_orig;
    } elseif ($width / $height > $ratio_orig) {
        $width = $height * $ratio_orig;
    } else {
        $height = $width / $ratio_orig;
    }
    bu::lib('opt/smart_resize_image/smart_resize_image.function');
    smart_resize_image($origName, $width, $height, false, $destName, false);
}
Example #16
0
 public function resize($inputPath, $outputPath, $width, $height)
 {
     smart_resize_image($inputPath, $width, $height, false, $outputPath, false, false, 100);
 }
Example #17
0
         } else {
             if ($tmp_tab_path_info[4] == 1) {
                 $url = __uploaddirfront__ . "tbl_" . __racinebd__ . $table . $tmp_tab_path_info[3] . "_" . $tmp_tab_path_info[2] . "." . $ext;
             } else {
                 $url = __uploaddirfront__ . "tbl_" . $tmp_tab_path_info[4] . "_" . __racinebd__ . $table . $tmp_tab_path_info[3] . "_" . $tmp_tab_path_info[2] . "." . $ext;
             }
         }
     }
     if ($resize) {
         $size = explode("x", $tmp_tab_path_info[5]);
         $newurl = __cachefolderimg__ . "/" . $tmp_tab_path_info[2] . "/" . implode("_", $tmp_tab_path_info) . "." . $ext;
         if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $newurl)) {
             if (!is_dir($_SERVER["DOCUMENT_ROOT"] . __cachefolderimg__ . "/" . $tmp_tab_path_info[2])) {
                 mkdir($_SERVER["DOCUMENT_ROOT"] . __cachefolderimg__ . "/" . $tmp_tab_path_info[2]);
             }
             smart_resize_image($_SERVER["DOCUMENT_ROOT"] . $url, $size[0], $size[1], true, $_SERVER["DOCUMENT_ROOT"] . $newurl, false);
         }
         $url = $newurl;
     }
     readfile($_SERVER["DOCUMENT_ROOT"] . $url);
     die;
 }
 if (trim($tmp_tab_path_info[1]) == "download") {
     if (trim($tmp_tab_path_info[2]) == "all") {
         $tbl_info = node($tmp_tab_path_info[3]);
         $tbl_file = contextfile($tmp_tab_path_info[3]);
         //creation du répertoire
         //print $_SERVER["DOCUMENT_ROOT"].__uploaddirfront__."arbre".$tab_path_info[3];
         @mkdir($_SERVER["DOCUMENT_ROOT"] . __uploaddirfront__ . "arbre" . $tmp_tab_path_info[3]);
         //copie des fichiers
         for ($i = 0; $i < count($tbl_file); $i++) {
    chdir($uploader->SaveDirectory);
    $wd = getcwd();
    chdir($cwd);
    $targetfilepath = "../uploads/" . $mvcfile->FileName;
    if (file_exists($targetfilepath)) {
        unlink($targetfilepath);
    }
    $mvcfile->CopyTo($targetfilepath);
    // After image copy we will resize it
    // $uploader->WriteValidationError(pathinfo($targetfilepath, PATHINFO_DIRNAME ).'/'.);
    // exit(200);
    $file = $targetfilepath;
    $extension = pathinfo($targetfilepath, PATHINFO_EXTENSION);
    $resizedFile = str_replace('.' . $extension, '_600.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 600, 400, false, $resizedFile, false, false, 100);
    $resizedFile = str_replace('.' . $extension, '_700.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 700, 400, false, $resizedFile, false, false, 100);
    $resizedFile = str_replace('.' . $extension, '_800.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 800, 200, false, $resizedFile, false, false, 100);
    $resizedFile = str_replace('.' . $extension, '_900.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 900, 400, false, $resizedFile, false, false, 100);
    $resizedFile = str_replace('.' . $extension, '_1000.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 1000, 400, false, $resizedFile, false, false, 100);
    $resizedFile = str_replace('.' . $extension, '_14.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 600, 500, false, $resizedFile, false, false, 100);
    $resizedFile = str_replace('.' . $extension, '_65.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 600, 600, false, $resizedFile, false, false, 100);
    $resizedFile = str_replace('.' . $extension, '_75.' . $extension, $targetfilepath);
    smart_resize_image($file, null, 700, 500, false, $resizedFile, false, false, 100);
}
$uploader->WriteValidationOK("");
Example #19
0
<?php

// pokreće se iz konzole, napraviti interfejs
// smanjuje sve slike iz foldera images na visinu 200px i izvozi ih u slike/smanjene
ini_set('memory_limit', '-1');
require "../biblioteke/smart-resize.php";
$ulazniFolder = "../../images";
$izlazniFolder = "../slike/smanjene";
$fajlovi = glob($ulazniFolder . "/*.*");
$duzina_niza = count($fajlovi);
for ($i = 0; $i <= $duzina_niza; $i++) {
    $filePath = $fajlovi[$i];
    $ext = pathinfo($filePath, PATHINFO_EXTENSION);
    $ext = "." . $ext;
    // dodaje tacku ekstenziji
    $newPath = str_replace($ulazniFolder, $izlazniFolder, $filePath);
    $newPath = str_replace($ext, "-200px" . $ext, $newPath);
    // pravi novo ime
    echo $filePath . "\r\n";
    echo $newPath . "\r\n";
    echo "\r\n";
    smart_resize_image($filePath, null, 0, 200, true, $newPath, false, false, 100);
}
Example #20
0
function tbl_img($table, $id, $ext, $width, $height, $vignette = false, $indice = '')
{
    $newname = $vignette == true ? $_SERVER["DOCUMENT_ROOT"] . __uploaddir__ . "tbl_" . $indice . $table . $id . "." . $ext : $_SERVER["DOCUMENT_ROOT"] . __uploaddir__ . $table . $id . "." . $ext;
    //resizeImg($_SERVER["DOCUMENT_ROOT"].__uploaddir__.$table.$id.".".$ext,$_SERVER["DOCUMENT_ROOT"].__uploaddir__.$table.$id.".".$ext,$width,$height);
    //smart_resize_image( $_SERVER["DOCUMENT_ROOT"].__uploaddir__.$table.$id.".".$ext, $width, $height, true, $newname,!$vignette);
    //print "<script>alert('".$table."ici')";
    $return = smart_resize_image($_SERVER["DOCUMENT_ROOT"] . __uploaddir__ . $table . $id . "." . $ext, $width, $height, false, $newname, !$vignette);
    //print "<script>alert('".$return."fin')";
}
Example #21
-1
            $album_photos = $response_album_photos->getGraphObject()->asArray();
            $num1 = count($album_photos['data']) + 1;
            $num2 = count($album_photos['data']);
            $num3 = $num1 - $num2;
            if (!empty($album_photos)) {
                foreach ($album_photos['data'] as $album_photo) {
                    $album_photo = (array) $album_photo;
                    foreach ($album as $key => $value) {
                        //echo '</br></br>';
                        //echo $value;
                    }
                    if ($album['name'] == $value && $num3 == 1) {
                        $album_cover_photo = $album_photo['source'];
                        $album_resized_cover_photo = 'libs/resources/albums/covers/' . $album['id'] . '_350X420.jpg';
                        if (!file_exists($album_resized_cover_photo)) {
                            smart_resize_image($album_cover_photo, null, 350, 420, false, $album_resized_cover_photo, false, false, 100);
                        }
                        ?>
												<div class="col-sm-6 col-md-4">
													<div class="thumbnail no-border center">
														
														<a href="<?php 
                        echo $album_photo['source'];
                        ?>
" class="fancybox" rel="<?php 
                        echo $album['id'];
                        ?>
">
														  <img src="<?php 
                        echo $album_resized_cover_photo;
                        ?>