Last active
December 23, 2017 18:44
-
-
Save erenkeskin/4b6492f908801c75c6fa9b0f42da7836 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php /* | |
1. Kısım | |
*/ | |
if (get_the_ID() && get_post_thumbnail_id(get_the_ID())) { // Yazının yada Resimin ID'si varsa | |
$resimDizi = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full'); //ORGINAL RESİM BOYUTU - default = full | |
$resimAdres = $resimDizi[0]; // Dizideki resim URL'si | |
$resimYol = realpath(str_replace(get_bloginfo('url'), '.', $resimAdres)); | |
$isim = basename($resimYol); | |
$yeniResimYolu = str_replace($isim, 'onek_' . $isim, $resimYol); // Yeni kayıttaki ön ek - "onek_" ister değiştirin istereniz silin | |
$yeniResimAdres = str_replace($isim, 'onek_' . $isim, $resimAdres); | |
if (!file_exists($yeniResimYolu)) { | |
$degisecekResim = wp_get_image_editor($resimYol); // Hayat kurtaracak kodumuz | |
if (!is_wp_error($degisecekResim)) { | |
$degisecekResim->resize(120, 120, true); // Resimi 120x120 yeniden boyutlandırma, true kesme işlemini temsil ediyor | |
$degisecekResim->save($yeniResimYolu); // Resmi yeniden ön eke sahip olarak kayıt ediyor. | |
} | |
} | |
} | |
/* | |
2. Kısım | |
*/ | |
function ocgBoyut($resimID, $genislik = 100, $yukseklik = 100) { // Öne Çıkarılan Görsel Boyutlandırma Fonksiyonu | |
$resimDizi = wp_get_attachment_image_src($resimID, 'full'); | |
$resimAdres = $resimDizi[0]; // Dizideki resim URL'si | |
$resimYol = realpath(str_replace(get_bloginfo('url'), '.', $resimAdres)); | |
$isim = basename($resimYol); | |
$yeniResimYolu = str_replace($isim, 'onek_' . $isim, $resimYol); // Yeni kayıttaki ön ek - "onek_" ister değiştirin istereniz silin | |
$yeniResimAdres = str_replace($isim, 'onek_' . $isim, $resimAdres); | |
if (!file_exists($yeniResimYolu)) { | |
$degisecekResim = wp_get_image_editor($resimYol); // Hayat kurtaracak kodumuz | |
if (!is_wp_error($degisecekResim)) { | |
$degisecekResim->resize($genislik, $yukseklik, true); // Resimi Genislik x Yukseklik olarak yeniden boyutlandırma, true kesme işlemini temsil ediyor | |
$degisecekResim->save($yeniResimYolu); // Resmi yeniden ön eke sahip olarak kayıt ediyor. | |
} | |
} | |
return $yeniResimAdres; | |
} | |
?> | |
/* | |
3. Kısım | |
*/ | |
<?php $onecikarilanResim = ocgBoyut(get_post_thumbnail_id(), GENİSLİK, YUKSEKLİK); ?> | |
<img src="<?php echo $onecikarilanResim; ?>" width="GENİSLİK" height="YUKSEKLİK" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment