function get_thumbnail($url) { $this->load->library('upload'); $url_original = $url; if (parse_url($url)) { $url = $this->addhttp($url); $url = parse_url($url); switch ($url['host']) { case 'www.youtube.com': parse_str($url['query'], $data); $video = $data['v']; $video_data = get_json("https://www.googleapis.com/youtube/v3/videos?id={$video}&part=snippet&key=AIzaSyBRa_48GW6LpDcB8VlQxrt5alf-4-GTThQ"); $thumbnail = $video_data->items[0]->snippet->thumbnails->high->url; break; case 'youtu.be': $video = str_replace('/', '', $url['path']); $json = get_json("https://www.googleapis.com/youtube/v3/videos?id={$video}&part=snippet&key=AIzaSyBRa_48GW6LpDcB8VlQxrt5alf-4-GTThQ"); $video_data = json_decode($json); $thumbnail = $video_data->items[0]->snippet->thumbnails->high->url; break; case 'www.dailymotion.com': $path = explode('/', $url['path']); $video = $path[2]; $thumbnail = "http://www.dailymotion.com/thumbnail/video/{$video}"; break; case 'vimeo.com': $path = explode('/', $url['path']); $video = end($path); $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/{$video}.php")); $thumbnail = $hash[0]['thumbnail_large']; break; case 'www.mmpro.de': $this->load->library('simple_html_dom'); $html = file_get_html($url_original); foreach ($html->find('link[rel=canonical]') as $element) { $canonical_url = $element->href; } $canonical_url = $this->addhttp($canonical_url); $canonical_url = parse_url($canonical_url); parse_str($canonical_url['query'], $data); $video_id = $data['videoId']; $json_output = get_json("http://www.mmpro.de/cache/videolist.json", true); foreach ($json_output as $object) { foreach ($object as $video) { $video_to_display = $video; foreach ($video["video"] as $video_data) { $video_uri = $video_data['uri']; if ($video_data['uri'] == $video_id) { break 3; } } } } if (isset($video_to_display['mcf'])) { $thumbnail = "http://www.mcfootage.com/imagereplace.php?width=900&height=600&kunde=archive&file=" . $video_to_display['picture']; } else { $json_output = get_json("http://www.admiralcloud.com/player/json/" . $video_uri); $thumbnail = $json_output->movies[0]->jpg; } break; case 'www.tvbvideo.de': $CI =& get_instance(); $CI->load->library('simple_html_dom'); $html = file_get_html($url_original); $r = html_entity_decode($html->find('#export_website_code', 0)->innertext()); $r_html = str_get_html($r); preg_match('(http://api.kewego.com/video/getHTML5Thumbnail.+\\"\\))', $r_html, $thumbnail); $thumbnail = substr($thumbnail[0], 0, -2); $thumbnail = $this->get_final_url($thumbnail); break; default: echo "Je ne connais pas ce site web... Veuillez vérifier le lien."; break; } if (isset($thumbnail) && $thumbnail != "assets/img/nopic.jpg") { //UPLOAD THUMBNAILS $filename = 'import_' . slug($_POST['title']) . '.jpg'; grab_image($thumbnail, $this->photos_path . $filename); $data['filename'] = $filename; if (autoCrop($data)) { create_thumbnail($data); create_header($data); unlink($this->photos_path . $filename); } return $filename; } else { if ($thumbnail == "assets/img/nopic.jpg") { return "nopic.jpg"; } else { return false; } } } else { return false; } }
echo '</tr>'; } echo '</tbody>'; echo '<table>'; } echo '<style>td{padding: 2px 5px;}</style><pre>'; die('Done!'); } if (isset($_GET['type']) && $_GET['type'] == 'featured') { $featured = $results->filter(function (&$v) { return $v->type == '_featured_image'; }); ini_set('max_execution_time', 300); $failed = array(); foreach ($featured as $image) { $x = autoCrop(0, $image->path, $image->type); // echo $image->path . '<br>'; // echo $image->type . '<br>'; // var_dump($x); if ($x === false) { $failed[] = $image->toArray(); } // echo '<hr>'; } if ($failed) { echo '<table style="border-color: #048108 !important;border-spacing: 0;" border="1" cellpadding="0">'; echo '<thead style="background: #048108; color: white; font-weight: bold;">'; echo '<tr>'; echo '<td>Type</td>'; echo '<td>Image type</td>'; echo '<td>Image path</td>';
function addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, $fieldName) { list($source_image_width, $source_image_height, $source_image_type) = getimagesize($destinationPath . $picture); $imageObjectInfo = array(); $imageObjectInfo['width'] = $source_image_width; $imageObjectInfo['height'] = $source_image_height; $imageObjectInfo['fileName'] = $filename; $imageObjectInfo['filePath'] = $newfileName . '.' . $extension; $imageObjectInfo['sizes'] = array(); $x = autoCrop($destinationPath, $picture, $fieldName); if ($x !== false) { $round = (int) \App\ResizesTinypng::max('round') + 1; insertIntoTableResizes($round, getTheImageSize($picture, $fieldName), $destinationPath . 'cropped/' . getTheImageSize($picture, $fieldName), 0, 'N', 0, false); $results_table = selectByRoundNumber($round); if (!empty($results_table)) { foreach ($results_table as $res_row) { $result_array = array('id' => intval($res_row['id']), 'round' => intval($res_row['round']), 'filename' => $res_row['file_name'], 'path' => $res_row['path'], 'runTiny' => intval($res_row['run_tiny']), 'error' => $res_row['error'], 'timeTiny' => intval($res_row['time_tiny']), 'timeAdded' => intval($res_row['created_at'])); $row_obj = array_to_object($result_array); $error_message = "N"; //START >> tinify images $tmp_path = str_replace(getcwd() . '/', "", $row_obj->path); //GET SERVER PATH $save_path = str_replace($row_obj->filename, "", $tmp_path); //OVERRIDE CURRENT LOCATION $flag = tinifyImage($row_obj->path, $save_path); if ($flag === false) { if ($error_message == "N") { $error_message = "Y - Compression failed"; } else { $error_message .= " - Compression failed"; } } //END << tinify image //UPDATE DB updateTableResizes($row_obj->id, $row_obj->round, $row_obj->filename, $row_obj->path, 1, $error_message, time(), $row_obj->timeAdded); } } } /* if ($source_image_width > 1920) {//} || $source_image_height > 1080) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1920, 1080); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['large'] = $imageInfo; } if ($source_image_width > 1024) { // || $source_image_height > 768) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1024, 768); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['medium'] = $imageInfo; } if ($source_image_width > 350) {//|| $source_image_height > 350) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 350, 350); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['small'] = $imageInfo; } if ($source_image_width > 300) {//|| $source_image_height > 350) { Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 300, 300); list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension); rename( $destinationPath . $newfileName . '-resized.'. $extension, $destinationPath . $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension); $imageInfo = array(); $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih . '.'. $extension; $imageInfo['width'] = $siw; $imageInfo['height'] = $sih; $imageInfo['mimeType'] = $mimeType; $imageObjectInfo['sizes']['thumbnail'] = $imageInfo; } */ // Save image object if ($imageObjectId = ObjectMeta::getValue($object->id, $fieldName)) { $imageObject = Object::find($imageObjectId); } if (empty($imageObject)) { $imageObject = new Object(); } $imageObject->author_id = Auth::user()->id; $imageObject->type = 'image'; $imageObject->name = $newfileName . '.' . $extension; $imageObject->title = $filename; $imageObject->status = 'inherit'; $imageObject->guid = $newfileName; $imageObject->save(); ObjectMeta::setValue($imageObject->id, '_file_path', $newfileName . '.' . $extension); ObjectMeta::setValue($imageObject->id, '_image_info', serialize($imageObjectInfo)); ObjectMeta::setValue($object->id, $fieldName, $imageObject->id); return $imageObject; }