コード例 #1
0
ファイル: main1.php プロジェクト: TristanMarion/Image-Panel
<?php

// On met les images une par une dans l'image finale
foreach ($images as $value) {
    $complete_name = download_image($value);
    $complete_name_path = 'src/' . $complete_name;
    $extension = substr($complete_name, strrpos($complete_name, ".") + 1);
    // En fonction du format de l'image téléchargée on la stocke dans une ressource du même type
    if ($extension == 'png') {
        $current_image = imagecreatefrompng($complete_name_path);
    } elseif ($extension == 'jpg' || $extension == 'jpeg') {
        $current_image = imagecreatefromjpeg($complete_name_path);
    } elseif ($extension == 'gif') {
        $current_image = imagecreatefromgif($complete_name_path);
    }
    // Redimensionnement : 100px de large mais le ratio est conservé
    list($width, $height) = getimagesize($complete_name_path);
    $new_height = $height;
    if ($width > 100) {
        imagecopyresized($current_image, $current_image, 0, 0, 0, 0, 100, $height / ($width / 100), $width, $height);
        $new_height = $height / ($width / 100);
    }
    // Suppression de l'image stockée en local
    unlink($complete_name_path);
    // Si une option de nom a été choisie
    if ($nom > 0) {
        ajout_nom($current_image, $height, $new_height, $width, $name, $complete_name, $nom);
    }
    // Si l'image ne rentre pas dans l'image finale on adapte la taille de cette dernière
    if ($dimensions_colonne[$x_index] + $new_height > $hauteur_max) {
        $new_montage_image = imagecreatetruecolor(100 * $x_max, $dimensions_colonne[$x_index] + $new_height);
コード例 #2
0
ファイル: index.php プロジェクト: arthaud/write-ups-2016
    } else {
        $_SESSION = unserialize(file_get_contents('pickle'));
    }
}
function download_image($url)
{
    $url = parse_url($origUrl = $url);
    if (isset($url['scheme']) && $url['scheme'] == 'http') {
        if ($url['path'] == '/avatar.png') {
            system('/usr/bin/wget ' . escapeshellarg($origUrl));
        }
    }
}
if (!isset($_SESSION['id'])) {
    $sessId = bin2hex(openssl_random_pseudo_bytes(10));
    $_SESSION['id'] = $sessId;
} else {
    $sessId = $_SESSION['id'];
}
session_write_close();
set_context($sessId);
if (isset($_POST['image'])) {
    download_image($_POST['image']);
}
?>

<img src="/data/<?php 
echo $sessId;
?>
/avatar.png" width=80 height=80 />
コード例 #3
0
ファイル: routes.php プロジェクト: shegun-babs/dakrush
    foreach ($html->find('dd[class=wp-caption-text]') as $element) {
        $names[] = trim($element->plaintext);
    }
    $counter = 0;
    foreach ($html->find('dt img') as $element) {
        $product_id = '';
        $long_name = $names[$counter];
        $trim_name = trim(before("{", $long_name));
        $name = ucwords($trim_name);
        $dimensions = between("{", "}", $long_name);
        $length = before("X", $dimensions) . "cm";
        $width = trim(after("X", $dimensions));
        $imageUrl = $element->{"data-orig-file"};
        $imageName = create_slug($trim_name) . '.jpg';
        $downloadPath = "tests/{$imageName}";
        download_image($imageUrl, $downloadPath);
        $data[$counter]['image'] = $imageUrl;
        $data[$counter]['name'] = $name;
        $data[$counter]['type'] = $trim_name;
        $data[$counter]['length'] = $length;
        $data[$counter]['thickness'] = NULL;
        $data[$counter]['width'] = $width;
        $data[$counter]['description'] = $long_name;
        $data[$counter]['hidden'] = 0;
        $counter++;
        echo "{$counter}, {$name} - (length){$length} - (width){$width}" . "<br/>" . '<img scr="' . $downloadPath . '"/>' . "<br/>";
    }
});
Route::group(['prefix' => 'tests'], function () {
    Route::get('wallpanel/{id}', 'ProductController@productView');
});
コード例 #4
0
ファイル: DownImage.php プロジェクト: OldMo/3DPrintProject
<?php

set_time_limit(0);
$products = simplexml_load_file('products.xml');
$items = $products->item;
$index = 0;
foreach ($items as $it) {
    $urls = $it->ColorImgUrl->url;
    foreach ($urls as $u) {
        if (strcasecmp($u, 'null') != 0) {
            echo $u . '<br/>';
            download_image($u, 'old', 'C:\\xampp\\htdocs\\crawl');
        }
    }
}
function download_image($url, $fileName = '', $dirName, $type = 0)
{
    if ($url == '') {
        return false;
    }
    // 获取远程文件资源方式选择
    if ($type) {
        echo '1';
        $ch = curl_init();
        $timeout = 300;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $file = curl_exec($ch);
        curl_close($ch);
    } else {
コード例 #5
0
/**
 * Импортирование продукта из xml
 * @param array $item
 * @param null $params
 * @return mixed
 */
function importPost(array $item, $params = NULL)
{
    /*
     * If connected woocommerce plugin - add posts to post type of woocommerce
     */
    include_once ABSPATH . 'wp-admin/includes/plugin.php';
    if (!is_plugin_active('woocommerce/woocommerce.php')) {
        echo "Для корректной работы этого плагина, необходимо установить Woocommerce плагин.";
        die;
    }
    $product_params = $params;
    global $wpdb;
    $rd_args = array('post_type' => 'product', 'meta_key' => 'offer_id', 'meta_value' => $item['id']);
    $q = new WP_Query($rd_args);
    $obItem = @$q->posts[0];
    //$obItem = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE ID = {$item['id']}");
    $postId = null;
    if (!empty($obItem->ID)) {
        if ($obItem->post_status == 'trash') {
            return;
        }
        if (!$obItem->post_modified || $obItem->post_date != $obItem->post_modified) {
            $item['title'] = $obItem->post_title;
            $item['description'] = $obItem->post_content;
        }
        $params = array('ID' => $obItem->ID, 'post_title' => $item['title'], 'post_content' => $item['description'], 'post_type' => 'product', 'post_name' => transliteration($item['title']));
        if (get_post_meta($obItem->ID, 'edited_by_user', TRUE)) {
            unset($params['post_title']);
            unset($params['post_content']);
            unset($params['post_name']);
        }
        wp_update_post($params);
        //set gdeslon offer_id
        update_post_meta($obItem->ID, 'offer_id', $item['id']);
        //set gdeslon url
        if ($item['url']) {
            update_post_meta($obItem->ID, 'url', $item['url'], get_post_meta($obItem->ID, 'url', TRUE));
        }
        //set gdeslon price
        if ($item['price']) {
            update_post_meta($obItem->ID, '_regular_price', $item['price'], get_post_meta($obItem->ID, '_regular_price', TRUE));
            update_post_meta($obItem->ID, '_price', $item['price'], get_post_meta($obItem->ID, '_price', TRUE));
            update_post_meta($obItem->ID, '_visibility', 'visible', get_post_meta($obItem->ID, '_visibility', TRUE));
            update_post_meta($obItem->ID, '_stock_status', 'instock', get_post_meta($obItem->ID, '_stock_status', TRUE));
        }
        $postId = $obItem->ID;
    } else {
        $postId = wp_insert_post(array('post_title' => $item['title'], 'post_content' => $item['description'], 'post_type' => 'product', 'post_status' => 'publish', 'post_mime_type' => $item['id'], 'comment_status' => 'closed', 'post_name' => transliteration($item['title'])));
        //set gdeslon offer_id
        add_post_meta($postId, 'offer_id', $item['id']);
        //set gdeslon url
        if ($item['url']) {
            add_post_meta($postId, 'url', $item['url'], TRUE);
        }
        //set gdeslon price
        if ($item['price']) {
            add_post_meta($postId, '_regular_price', $item['price'], TRUE);
            add_post_meta($postId, '_price', $item['price'], TRUE);
            add_post_meta($postId, '_visibility', 'visible', TRUE);
            add_post_meta($postId, '_stock_status', 'instock', TRUE);
        }
        add_post_meta($postId, '_wp_page_template', 'sidebar-page.php', TRUE);
    }
    /**
     * Подгрузка изображения
     */
    if (!empty($item['image'])) {
        download_image($item['image'], $postId);
    }
    wp_set_object_terms($postId, array(intval(get_category_by_outer_id($item['category_id'])->term_id)), 'product_cat');
    //add product params
    $attributes = array();
    unset($product_params['params_list']);
    unset($product_params['vendor']);
    foreach ($product_params as $name => $value) {
        $attributes[htmlspecialchars(stripslashes($name))] = array('name' => htmlspecialchars(stripslashes($name)), 'value' => $value, 'position' => 1, 'is_visible' => 1, 'is_variation' => 1, 'is_taxonomy' => 0);
    }
    set_product_attributes($postId, $attributes);
}
コード例 #6
0
ファイル: wp_helper.php プロジェクト: RobertDuy/trippacker
function c_set_post_thumbnail($post_id, $filename, $image_temp)
{
    set_post_thumbnail($post_id, download_image($post_id, $filename, $image_temp));
}