v2.5.2
Giriş yap

for içerisinde if yada switch case kullanmak

rotaile
349 defa görüntülendi

arkadaşlar selam, sorunum for içerisinde ki for da olan x değerini $i değeri 3 yada 6 olduğu zaman x ve y değerlini değiştirmek. ama şöyle bir sorun oluyor $i değeri 3 olduğu zaman döngü devam etmiyor nedeni nedir? (aynı şekilde if ile de denedim yine aynı yerde takıldı döngü)

$mimeType = $request->file('sharedPhoto')->extension();
$img = Image::make('img/shared-photos/27-06-2022_17-09-31-faruk-savur.jpg');

$y = 0;
$x = 0;
for ($i = 1; $i <= 9; $i++) {
    for ($x; $x <= 400; $x += 200) {
        switch ($i) {
            case 3:
                $x = 0;
                $y = 200;
                break;
            case 6:
                $x = 0;
                $y = 400;
                break;
        }
        //print ("i: " . $i . "<br>");
        $img->crop(200, 200, $x, $y)->save('img/shared-photos/' . $i . '.' . $mimeType);
    }
}
rotaile
667 gün önce
$mimeType = $request->file('sharedPhoto')->extension();//dosya uzantısı
$nineGrid = $request->nineGrid;//9 parça olacak mı ? on : ""
$photoName = Auth::user()->id . "." . $mimeType;//600*600 geçici olan resmin adı
Image::make(request()->file('sharedPhoto'))->fit(600, 600)->save('img/shared-photos/' . $photoName);//600*600 resmi küçült ve geçici olarak kaydet
if ($nineGrid) {//olsun reyis 9 parça olsun
    $i = 0;
    for ($a = 0; $a <= 400; $a += 200) {
        $y = 0;
        $i++;
        $img = Image::make('img/shared-photos/' . Auth::user()->id . '.' . $mimeType);
        $photoName = $i . "-" . date('d-m-Y_H-i-s') . "-" . Auth::user()->userName . "-" . Auth::user()->userSurname . "-" . "." . $mimeType;//yeni dosya adı
        $img->crop(200, 200, $a, $y)->save('img/shared-photos/' . $photoName);
        Photos::create([
            "photoPath" => 'img/shared-photos/' . $photoName,
            "photoDescription" => $i,
            "userId" => Auth::user()->id,
        ]);
        //print ("x: " . $a . " <b>-*-</b> " . "y: " . $y . "<br>");
    }
    for ($b = 0; $b <= 400; $b += 200) {
        $y = 200;
        $i++;
        $img = Image::make('img/shared-photos/' . Auth::user()->id . '.' . $mimeType);
        $photoName = $i . "-" . date('d-m-Y_H-i-s') . "-" . Auth::user()->userName . "-" . Auth::user()->userSurname . "." . $mimeType;//yeni dosya adı
        $img->crop(200, 200, $b, $y)->save('img/shared-photos/' . $photoName);
        Photos::create([
            "photoPath" => 'img/shared-photos/' . $photoName,
            "photoDescription" => $i,
            "userId" => Auth::user()->id,
        ]);
        //print ("x: " . $b . " <b>-*-</b> " . "y: " . $y . "<br>");
    }
    for ($c = 0; $c <= 400; $c += 200) {
        $y = 400;
        $i++;
        $img = Image::make('img/shared-photos/' . Auth::user()->id . '.' . $mimeType);
        $photoName = $i . "-" . date('d-m-Y_H-i-s') . "-" . Auth::user()->userName . "-" . Auth::user()->userSurname . "." . $mimeType;//yeni dosya adı
        $img->crop(200, 200, $c, $y)->save('img/shared-photos/' . $photoName);
        Photos::create([
            "photoPath" => 'img/shared-photos/' . $photoName,
            "photoDescription" => $i,
            "userId" => Auth::user()->id,
        ]);
        //print ("x: " . $c . " <b>-*-</b> " . "y: " . $y . "<br>");
    }
    $isFile = file_exists('img/shared-photos/' . Auth::user()->id . '.' . $mimeType);//böyle bir dosya varsa
    if ($isFile) {
        unlink("img/shared-photos/" . Auth::user()->id . '.' . $mimeType);//eski fotoğrafı sil
    }
    toastr()->success('Fotoğraflar paylaşıldı.', 'İşlem başarılı ' . Str::ucfirst(Auth::user()->userName));
    return redirect()->route('kullanicilar', ['userFullname' => Auth::user()->userFullname])->with('sharedBtnPhoto', 'active')->with('userSharedTab', 'show active');

ben şu şekilde yaptım ne kadar mantıklı oldu bilmiyorum ama sağlıklı çalışıyor. (şimdilik :/)